Skip to content

Commit

Permalink
Added git-binary-file-path config variable
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rgburke committed Jun 24, 2018
1 parent b934174 commit 8fa87fd
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 30 deletions.
7 changes: 7 additions & 0 deletions cmd/grv/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const (
cfCommitGraphDefaultValue = false
cfConfirmCheckoutDefaultValue = true
cfPromptHistorySizeDefaultValue = 1000
cfGitBinaryFilePathDefaultValue = ""

cfAllView = "All"
cfMainView = "MainView"
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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 {
Expand Down
19 changes: 9 additions & 10 deletions cmd/grv/grv.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand All @@ -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
}
Expand All @@ -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
Expand Down
39 changes: 30 additions & 9 deletions cmd/grv/repo_data_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
}
}

Expand Down Expand Up @@ -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")
Expand All @@ -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")
Expand All @@ -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
Expand Down
12 changes: 10 additions & 2 deletions cmd/grv/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down Expand Up @@ -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)
Expand Down
19 changes: 10 additions & 9 deletions doc/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```


Expand Down

0 comments on commit 8fa87fd

Please sign in to comment.