summaryrefslogtreecommitdiffstats
path: root/gitcommands.go
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2018-08-06 19:01:27 +1000
committerJesse Duffield <jessedduffield@gmail.com>2018-08-06 19:01:27 +1000
commitcf73d4f558a1c180a52f9be4768aa9b754d4b4b3 (patch)
tree085e6af51794f55493882954057a9fd8a10dcf27 /gitcommands.go
parentb1918f2f688891efd34a190a210f10ec35c160f3 (diff)
standardise error handling of command functions
Diffstat (limited to 'gitcommands.go')
-rw-r--r--gitcommands.go19
1 files changed, 11 insertions, 8 deletions
diff --git a/gitcommands.go b/gitcommands.go
index d537672a0..27e4e8369 100644
--- a/gitcommands.go
+++ b/gitcommands.go
@@ -119,8 +119,7 @@ func runDirectCommand(command string) (string, error) {
Command("bash", "-c", command).
CombinedOutput()
devLog("run direct command time for command: ", command, time.Now().Sub(timeStart))
-
- return string(cmdOut), err
+ return sanitisedCommandOutput(cmdOut, err)
}
func branchStringParts(branchString string) (string, string) {
@@ -299,17 +298,21 @@ func gitCheckout(branch string, force bool) (string, error) {
return runCommand("git checkout " + forceArg + branch)
}
+func sanitisedCommandOutput(output []byte, err error) (string, error) {
+ outputString := string(output)
+ if outputString == "" && err != nil {
+ return err.Error(), err
+ }
+ return outputString, err
+}
+
func runCommand(command string) (string, error) {
commandStartTime := time.Now()
commandLog(command)
splitCmd := strings.Split(command, " ")
cmdOut, err := exec.Command(splitCmd[0], splitCmd[1:]...).CombinedOutput()
devLog("run command time: ", time.Now().Sub(commandStartTime))
- outputString := string(cmdOut)
- if outputString == "" && err != nil {
- return err.Error(), err
- }
- return outputString, err
+ return sanitisedCommandOutput(cmdOut, err)
}
func openFile(filename string) (string, error) {
@@ -446,7 +449,7 @@ func removeFile(file GitFile) error {
}
func gitCommit(message string) (string, error) {
- return runCommand("git commit -m \"" + message + "\"")
+ return runDirectCommand("git commit -m \"" + message + "\"")
}
func gitPull() (string, error) {