summaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2023-07-16 18:12:26 +1000
committerJesse Duffield <jessedduffield@gmail.com>2023-07-30 18:35:22 +1000
commitae0193698e3540787b30696fabb8368ee483e9e1 (patch)
treec72fa6acd9ce66aabe5b0f530f2b1cd390092a5e /pkg
parent6b4a6384156451203bd4559f65563f03dbbdd5df (diff)
Log when directory is changed
Diffstat (limited to 'pkg')
-rw-r--r--pkg/commands/git_commands/worktree.go4
-rw-r--r--pkg/commands/oscommands/cmd_obj.go9
-rw-r--r--pkg/gui/controllers/branches_controller.go2
-rw-r--r--pkg/gui/controllers/helpers/repos_helper.go2
-rw-r--r--pkg/gui/controllers/helpers/worktree_helper.go10
5 files changed, 21 insertions, 6 deletions
diff --git a/pkg/commands/git_commands/worktree.go b/pkg/commands/git_commands/worktree.go
index 922dbb957..de3711628 100644
--- a/pkg/commands/git_commands/worktree.go
+++ b/pkg/commands/git_commands/worktree.go
@@ -33,9 +33,9 @@ func (self *WorktreeCommands) Delete(worktreePath string, force bool) error {
}
func (self *WorktreeCommands) Detach(worktreePath string) error {
- cmdArgs := NewGitCmd("checkout").Arg("--detach").WorktreePath(worktreePath).ToArgv()
+ cmdArgs := NewGitCmd("checkout").Arg("--detach").ToArgv()
- return self.cmd.New(cmdArgs).Run()
+ return self.cmd.New(cmdArgs).SetWd(worktreePath).Run()
}
func (self *WorktreeCommands) IsCurrentWorktree(w *models.Worktree) bool {
diff --git a/pkg/commands/oscommands/cmd_obj.go b/pkg/commands/oscommands/cmd_obj.go
index 520a76a1b..d1cc23c67 100644
--- a/pkg/commands/oscommands/cmd_obj.go
+++ b/pkg/commands/oscommands/cmd_obj.go
@@ -24,6 +24,9 @@ type ICmdObj interface {
AddEnvVars(...string) ICmdObj
GetEnvVars() []string
+ // sets the working directory
+ SetWd(string) ICmdObj
+
// runs the command and returns an error if any
Run() error
// runs the command and returns the output as a string, and an error if any
@@ -142,6 +145,12 @@ func (self *CmdObj) GetEnvVars() []string {
return self.cmd.Env
}
+func (self *CmdObj) SetWd(wd string) ICmdObj {
+ self.cmd.Dir = wd
+
+ return self
+}
+
func (self *CmdObj) DontLog() ICmdObj {
self.dontLog = true
return self
diff --git a/pkg/gui/controllers/branches_controller.go b/pkg/gui/controllers/branches_controller.go
index 62fa786b5..1935b8d1c 100644
--- a/pkg/gui/controllers/branches_controller.go
+++ b/pkg/gui/controllers/branches_controller.go
@@ -344,7 +344,7 @@ func (self *BranchesController) promptWorktreeBranchDelete(selectedBranch *model
Title: fmt.Sprintf("Branch %s is checked out by worktree %s", selectedBranch.Name, worktree.Name()),
Items: []*types.MenuItem{
{
- Label: "Switch to worktree " + worktree.Name(),
+ Label: "Switch to worktree",
OnPress: func() error {
return self.c.Helpers().Worktree.Switch(worktree, context.LOCAL_BRANCHES_CONTEXT_KEY)
},
diff --git a/pkg/gui/controllers/helpers/repos_helper.go b/pkg/gui/controllers/helpers/repos_helper.go
index 942cceef8..95bd7e94a 100644
--- a/pkg/gui/controllers/helpers/repos_helper.go
+++ b/pkg/gui/controllers/helpers/repos_helper.go
@@ -149,6 +149,8 @@ func (self *ReposHelper) DispatchSwitchTo(path string, reuse bool, errMsg string
return nil
}
+ self.c.LogCommand(fmt.Sprintf("Changing directory to %s", path), false)
+
if err := os.Chdir(path); err != nil {
if os.IsNotExist(err) {
return self.c.ErrorMsg(errMsg)
diff --git a/pkg/gui/controllers/helpers/worktree_helper.go b/pkg/gui/controllers/helpers/worktree_helper.go
index b00315fbd..64b518389 100644
--- a/pkg/gui/controllers/helpers/worktree_helper.go
+++ b/pkg/gui/controllers/helpers/worktree_helper.go
@@ -72,7 +72,7 @@ func (self *WorktreeHelper) NewWorktree() error {
if err := self.c.Git().Worktree.New(sanitizedBranchName(path), committish); err != nil {
return err
}
- return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC})
+ return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.WORKTREES, types.BRANCHES, types.FILES}})
})
},
})
@@ -122,7 +122,7 @@ func (self *WorktreeHelper) Remove(worktree *models.Worktree, force bool) error
}
return self.c.ErrorMsg(errMessage)
}
- return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.WORKTREES}})
+ return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.WORKTREES, types.BRANCHES, types.FILES}})
})
},
})
@@ -132,6 +132,10 @@ func (self *WorktreeHelper) Detach(worktree *models.Worktree) error {
return self.c.WithWaitingStatus(self.c.Tr.DetachingWorktree, func(gocui.Task) error {
self.c.LogAction(self.c.Tr.RemovingWorktree)
- return self.c.Git().Worktree.Detach(worktree.Path)
+ err := self.c.Git().Worktree.Detach(worktree.Path)
+ if err != nil {
+ return self.c.Error(err)
+ }
+ return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.WORKTREES, types.BRANCHES, types.FILES}})
})
}