summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Burke <rich.g.burke@gmail.com>2018-06-24 11:18:05 +0100
committerRichard Burke <rich.g.burke@gmail.com>2018-06-24 11:18:05 +0100
commit8fa87fd2d21bd9d58904602b01b365269c485af8 (patch)
tree54ad2ef82db7f49db61731c601ff7e06a362ab4f
parentb934174ddc3f46ab8723a7a5d52140278b2b134b (diff)
Added git-binary-file-path config variablev0.2.0
When grv falls back to using git it will first attempt to verify it can successfully call the git binary. If unsuccessful it will prompt the user with an error message to set the git-binary-file-path config variable.
-rw-r--r--cmd/grv/config.go7
-rw-r--r--cmd/grv/grv.go19
-rw-r--r--cmd/grv/repo_data_loader.go39
-rw-r--r--cmd/grv/ui.go12
-rw-r--r--doc/documentation.md19
5 files changed, 66 insertions, 30 deletions
diff --git a/cmd/grv/config.go b/cmd/grv/config.go
index b9702ba..577e106 100644
--- a/cmd/grv/config.go
+++ b/cmd/grv/config.go
@@ -32,6 +32,7 @@ const (
cfCommitGraphDefaultValue = false
cfConfirmCheckoutDefaultValue = true
cfPromptHistorySizeDefaultValue = 1000
+ cfGitBinaryFilePathDefaultValue = ""
cfAllView = "All"
cfMainView = "MainView"
@@ -68,6 +69,8 @@ const (
CfConfirmCheckout ConfigVariable = "confirm-checkout"
// CfPromptHistorySize stores the maximum number of prompt entries retained
CfPromptHistorySize ConfigVariable = "prompt-history-size"
+ // CfGitBinaryFilePath stores the file path to the git binary
+ CfGitBinaryFilePath ConfigVariable = "git-binary-file-path"
)
var systemColorValues = map[string]SystemColorValue{
@@ -317,6 +320,10 @@ func NewConfiguration(keyBindings KeyBindings, channels Channels) *Configuration
validator: promptHistorySizeValidator{},
description: "Maximum number of prompt entries retained",
},
+ CfGitBinaryFilePath: {
+ defaultValue: cfGitBinaryFilePathDefaultValue,
+ description: "File path to git binary. Required only when git binary is not in $PATH",
+ },
}
for _, configVariable := range config.variables {
diff --git a/cmd/grv/grv.go b/cmd/grv/grv.go
index 447189c..d75cc4b 100644
--- a/cmd/grv/grv.go
+++ b/cmd/grv/grv.go
@@ -173,8 +173,10 @@ func NewGRV(readOnly bool) *GRV {
}
channels := grvChannels.Channels()
+ keyBindings := NewKeyBindingManager()
+ config := NewConfiguration(keyBindings, channels)
- repoDataLoader := NewRepoDataLoader(channels)
+ repoDataLoader := NewRepoDataLoader(channels, config)
repoData := NewRepositoryData(repoDataLoader, channels)
var repoController RepoController
@@ -185,8 +187,6 @@ func NewGRV(readOnly bool) *GRV {
repoController = NewRepoController(repoData, channels)
}
- keyBindings := NewKeyBindingManager()
- config := NewConfiguration(keyBindings, channels)
ui := NewNCursesDisplay(channels, config)
view := NewView(repoData, repoController, channels, config)
@@ -208,6 +208,12 @@ func NewGRV(readOnly bool) *GRV {
func (grv *GRV) Initialise(repoPath, workTreePath string) (err error) {
log.Info("Initialising GRV")
+ channels := grv.channels.Channels()
+
+ if configErrors := grv.config.Initialise(); configErrors != nil {
+ channels.ReportErrors(configErrors)
+ }
+
if err = grv.repoInitialiser.CreateRepositoryInstance(repoPath, workTreePath); err != nil {
return
}
@@ -226,13 +232,6 @@ func (grv *GRV) Initialise(repoPath, workTreePath string) (err error) {
return
}
- if configErrors := grv.config.Initialise(); configErrors != nil {
- for _, configError := range configErrors {
- grv.channels.errorCh <- configError
- }
- }
-
- channels := grv.channels.Channels()
InitReadLine(channels, grv.config)
return
diff --git a/cmd/grv/repo_data_loader.go b/cmd/grv/repo_data_loader.go
index 585540d..7a5844e 100644
--- a/cmd/grv/repo_data_loader.go
+++ b/cmd/grv/repo_data_loader.go
@@ -36,10 +36,12 @@ type instanceCache struct {
// RepoDataLoader handles loading data from the repository
type RepoDataLoader struct {
- repo *git.Repository
- cache *instanceCache
- channels Channels
- diffErrorPresent bool
+ repo *git.Repository
+ cache *instanceCache
+ channels Channels
+ config Config
+ diffErrorPresent bool
+ gitBinaryConfirmed bool
}
// Oid is reference to a git object
@@ -600,10 +602,11 @@ func (cache *instanceCache) getCachedOid(oidStr string) (oid *Oid, exists bool)
}
// NewRepoDataLoader creates a new instance
-func NewRepoDataLoader(channels Channels) *RepoDataLoader {
+func NewRepoDataLoader(channels Channels, config Config) *RepoDataLoader {
return &RepoDataLoader{
cache: newInstanceCache(),
channels: channels,
+ config: config,
}
}
@@ -1140,14 +1143,14 @@ const (
func (repoDataLoader *RepoDataLoader) generateCommitDiffUsingCLI(commit *Commit) (diff *Diff, err error) {
log.Debugf("Attempting to load diff using cli for commit: %v", commit.oid.String())
- gitCommand := []string{"git", "show", "--encoding=UTF8", "--pretty=oneline", "--root", "--patch-with-stat", "--no-color", commit.oid.String()}
+ gitCommand := []string{"show", "--encoding=UTF8", "--pretty=oneline", "--root", "--patch-with-stat", "--no-color", commit.oid.String()}
return repoDataLoader.runGitCLIDiff(gitCommand, dtCommit)
}
func (repoDataLoader *RepoDataLoader) generateFileDiffUsingCLI(statusType StatusType, path string) (diff *Diff, err error) {
log.Debugf("Attempting to load diff using cli for StatusType: %v and file: %v", StatusTypeDisplayName(statusType), path)
- gitCommand := []string{"git", "diff"}
+ gitCommand := []string{"diff"}
if statusType == StStaged {
gitCommand = append(gitCommand, "--cached")
@@ -1163,7 +1166,7 @@ func (repoDataLoader *RepoDataLoader) generateFileDiffUsingCLI(statusType Status
func (repoDataLoader *RepoDataLoader) generateStageDiffUsingCLI(statusType StatusType) (diff *Diff, err error) {
log.Debugf("Attempting to load diff using cli for StatusType: %v", StatusTypeDisplayName(statusType))
- gitCommand := []string{"git", "diff"}
+ gitCommand := []string{"diff"}
if statusType == StStaged {
gitCommand = append(gitCommand, "--cached")
@@ -1176,10 +1179,28 @@ func (repoDataLoader *RepoDataLoader) generateStageDiffUsingCLI(statusType Statu
return repoDataLoader.runGitCLIDiff(gitCommand, dtStage)
}
+func (repoDataLoader *RepoDataLoader) gitBinary() string {
+ if gitBinary := repoDataLoader.config.GetString(CfGitBinaryFilePath); gitBinary != "" {
+ return gitBinary
+ }
+
+ return "git"
+}
+
func (repoDataLoader *RepoDataLoader) runGitCLIDiff(gitCommand []string, diffType diffType) (diff *Diff, err error) {
diff = &Diff{}
- cmd := exec.Command(gitCommand[0], gitCommand[1:]...)
+ if !repoDataLoader.gitBinaryConfirmed {
+ if exec.Command(repoDataLoader.gitBinary(), "version").Run() == nil {
+ repoDataLoader.gitBinaryConfirmed = true
+ } else {
+ err = fmt.Errorf("Unable to successfully call git binary. "+
+ "If git is not in $PATH then please set the config variable %v", CfGitBinaryFilePath)
+ return
+ }
+ }
+
+ cmd := exec.Command(repoDataLoader.gitBinary(), gitCommand...)
cmd.Env = repoDataLoader.GenerateGitCommandEnvironment()
var stdout, stderr bytes.Buffer
diff --git a/cmd/grv/ui.go b/cmd/grv/ui.go
index 05dc978..e896668 100644
--- a/cmd/grv/ui.go
+++ b/cmd/grv/ui.go
@@ -266,6 +266,10 @@ func (ui *NCursesUI) initialiseNCurses() (err error) {
gc.Raw(true)
gc.MouseInterval(0)
+ if ui.config.GetBool(CfMouse) {
+ ui.toggleMouse()
+ }
+
if gc.Cursor(0) != nil {
log.Debugf("Unable to hide cursor")
}
@@ -649,13 +653,17 @@ func (ui *NCursesUI) onConfigVariableChange(configVariable ConfigVariable) {
theme := ui.config.GetTheme()
ui.initialiseColorPairsFromTheme(theme)
case CfMouse:
- log.Infof("Toggling mouse enabled")
- gc.MouseMask(ui.mouseMask, &ui.mouseMask)
+ ui.toggleMouse()
default:
log.Warn("Received notification for variable I didn't register for: %v", configVariable)
}
}
+func (ui *NCursesUI) toggleMouse() {
+ log.Infof("Toggling mouse enabled")
+ gc.MouseMask(ui.mouseMask, &ui.mouseMask)
+}
+
func (ui *NCursesUI) initialiseColorPairsFromTheme(theme Theme) {
defaultComponent := theme.GetComponent(CmpAllviewDefault)
fgDefault := ui.getNCursesColor(defaultComponent.fgcolor)
diff --git a/doc/documentation.md b/doc/documentation.md
index 2ba2327..e8cc71b 100644
--- a/doc/documentation.md
+++ b/doc/documentation.md
@@ -166,15 +166,16 @@ Configuration variables allow features to be enabled, disabled and configured.
They are specified using the set command in the grvrc file or at the command prompt
```
- Variable | Type | Default Value | Description
- --------------------+--------+---------------+-----------------------------------------------
- commit-graph | bool | false | Commit graph visible
- confirm-checkout | bool | true | Confirm before performing git checkout
- mouse | bool | false | Mouse support enabled
- mouse-scroll-rows | int | 3 | Number of rows scrolled for each mouse event
- prompt-history-size | int | 1000 | Maximum number of prompt entries retained
- tabwidth | int | 8 | Tab character screen width (minimum value: 1)
- theme | string | solarized | The currently active theme
+ Variable | Type | Default Value | Description
+ ---------------------+--------+---------------+------------------------------------------------------------------------
+ commit-graph | bool | false | Commit graph visible
+ confirm-checkout | bool | true | Confirm before performing git checkout
+ git-binary-file-path | string | | File path to git binary. Required only when git binary is not in $PATH
+ mouse | bool | false | Mouse support enabled
+ mouse-scroll-rows | int | 3 | Number of rows scrolled for each mouse event
+ prompt-history-size | int | 1000 | Maximum number of prompt entries retained
+ tabwidth | int | 8 | Tab character screen width (minimum value: 1)
+ theme | string | solarized | The currently active theme
```