Skip to content

Commit 4281cc2

Browse files
committed
add git config check and editing ability
1 parent 8013f18 commit 4281cc2

File tree

4 files changed

+154
-6
lines changed

4 files changed

+154
-6
lines changed

Gopkg.lock

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gitcommands.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414

1515
"github.com/fatih/color"
1616
"github.com/jesseduffield/gocui"
17+
gitconfig "github.com/tcnksm/go-gitconfig"
1718
)
1819

1920
var (
@@ -267,6 +268,7 @@ func runCommand(command string) (string, error) {
267268
commandStartTime := time.Now()
268269
commandLog(command)
269270
splitCmd := strings.Split(command, " ")
271+
devLog(splitCmd)
270272
cmdOut, err := exec.Command(splitCmd[0], splitCmd[1:]...).CombinedOutput()
271273
devLog("run command time: ", time.Now().Sub(commandStartTime))
272274
return sanitisedCommandOutput(cmdOut, err)
@@ -308,14 +310,16 @@ func gitAddPatch(g *gocui.Gui, filename string) {
308310
}
309311

310312
func editFile(g *gocui.Gui, filename string) (string, error) {
311-
editor := os.Getenv("VISUAL")
313+
editor, _ := gitconfig.Global("core.editor")
314+
if editor == "" {
315+
editor = os.Getenv("VISUAL")
316+
}
312317
if editor == "" {
313318
editor = os.Getenv("EDITOR")
314319
}
315320
if editor == "" {
316-
editor = "vi"
321+
return "", createErrorPanel(g, "No editor defined in $VISUAL, $EDITOR, or git config.")
317322
}
318-
319323
runSubProcess(g, editor, filename)
320324
return "", nil
321325
}
@@ -455,9 +459,9 @@ func removeFile(file GitFile) error {
455459
}
456460

457461
func gitCommit(g *gocui.Gui, message string) (string, error) {
458-
out, _ := runDirectCommand("git config --get commit.gpgsign")
459-
if out != "" {
460-
runSubProcess(g, "git", "commit", "-m", "\""+message+"\"")
462+
gpgsign, _ := gitconfig.Global("commit.gpgsign")
463+
if gpgsign != "" {
464+
runSubProcess(g, "bash", "-c", "git commit -m \""+message+"\"")
461465
return "", nil
462466
}
463467
return runDirectCommand("git commit -m \"" + message + "\"")

vendor/github.com/tcnksm/go-gitconfig/LICENSE

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/tcnksm/go-gitconfig/gitconfig.go

Lines changed: 113 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)