summaryrefslogtreecommitdiffstats
path: root/pkg/commands/git_cmd_obj_runner.go
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2021-12-29 14:33:38 +1100
committerJesse Duffield <jessedduffield@gmail.com>2022-01-04 09:07:15 +1100
commit43a4fa970dfceb7868959ff4da48d5507fa2f234 (patch)
treedaff776e59aebeb9b814a7918a9db75d4443175f /pkg/commands/git_cmd_obj_runner.go
parent192a548c9957807d9d5c9c4700dffe02c1f55f03 (diff)
WIP
Diffstat (limited to 'pkg/commands/git_cmd_obj_runner.go')
-rw-r--r--pkg/commands/git_cmd_obj_runner.go49
1 files changed, 49 insertions, 0 deletions
diff --git a/pkg/commands/git_cmd_obj_runner.go b/pkg/commands/git_cmd_obj_runner.go
new file mode 100644
index 000000000..7529403cd
--- /dev/null
+++ b/pkg/commands/git_cmd_obj_runner.go
@@ -0,0 +1,49 @@
+package commands
+
+import (
+ "strings"
+ "time"
+
+ "github.com/jesseduffield/lazygit/pkg/commands/oscommands"
+ "github.com/sirupsen/logrus"
+)
+
+// here we're wrapping the default command runner in some git-specific stuff e.g. retry logic if we get an error due to the presence of .git/index.lock
+
+type gitCmdObjRunner struct {
+ log *logrus.Entry
+ innerRunner oscommands.ICmdObjRunner
+}
+
+func (self *gitCmdObjRunner) Run(cmdObj oscommands.ICmdObj) error {
+ _, err := self.RunWithOutput(cmdObj)
+ return err
+}
+
+func (self *gitCmdObjRunner) RunWithOutput(cmdObj oscommands.ICmdObj) (string, error) {
+ // TODO: have this retry logic in other places we run the command
+ waitTime := 50 * time.Millisecond
+ retryCount := 5
+ attempt := 0
+
+ for {
+ output, err := self.innerRunner.RunWithOutput(cmdObj)
+ if err != nil {
+ // if we have an error based on the index lock, we should wait a bit and then retry
+ if strings.Contains(output, ".git/index.lock") {
+ self.log.Error(output)
+ self.log.Info("index.lock prevented command from running. Retrying command after a small wait")
+ attempt++
+ time.Sleep(waitTime)
+ if attempt < retryCount {
+ continue
+ }
+ }
+ }
+ return output, err
+ }
+}
+
+func (self *gitCmdObjRunner) RunLineOutputCmd(cmdObj oscommands.ICmdObj, onLine func(line string) (bool, error)) error {
+ return self.innerRunner.RunLineOutputCmd(cmdObj, onLine)
+}