mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-12 12:55:47 +02:00
Add worktree tests for removing/detaching
This commit is contained in:
parent
277142fc4b
commit
b93b9dae88
9 changed files with 183 additions and 8 deletions
|
@ -42,20 +42,30 @@ func (self *GitCommandBuilder) Config(value string) *GitCommandBuilder {
|
|||
return self
|
||||
}
|
||||
|
||||
func (self *GitCommandBuilder) RepoPath(value string) *GitCommandBuilder {
|
||||
// the -C arg will make git do a `cd` to the directory before doing anything else
|
||||
func (self *GitCommandBuilder) Dir(path string) *GitCommandBuilder {
|
||||
// repo path comes before the command
|
||||
self.args = append([]string{"-C", value}, self.args...)
|
||||
self.args = append([]string{"-C", path}, self.args...)
|
||||
|
||||
return self
|
||||
}
|
||||
|
||||
func (self *GitCommandBuilder) WorktreePath(path string) *GitCommandBuilder {
|
||||
// worktree path comes before the command
|
||||
// Note, you may prefer to use the Dir method instead of this one
|
||||
func (self *GitCommandBuilder) Worktree(path string) *GitCommandBuilder {
|
||||
// worktree arg comes before the command
|
||||
self.args = append([]string{"--work-tree", path}, self.args...)
|
||||
|
||||
return self
|
||||
}
|
||||
|
||||
// Note, you may prefer to use the Dir method instead of this one
|
||||
func (self *GitCommandBuilder) GitDir(path string) *GitCommandBuilder {
|
||||
// git dir arg comes before the command
|
||||
self.args = append([]string{"--git-dir", path}, self.args...)
|
||||
|
||||
return self
|
||||
}
|
||||
|
||||
func (self *GitCommandBuilder) ToArgv() []string {
|
||||
return append([]string{"git"}, self.args...)
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ func TestGitCommandBuilder(t *testing.T) {
|
|||
expected: []string{"git", "-c", "user.email=bar", "-c", "user.name=foo", "push"},
|
||||
},
|
||||
{
|
||||
input: NewGitCmd("push").RepoPath("a/b/c").ToArgv(),
|
||||
input: NewGitCmd("push").Dir("a/b/c").ToArgv(),
|
||||
expected: []string{"git", "-C", "a/b/c", "push"},
|
||||
},
|
||||
}
|
||||
|
|
|
@ -82,7 +82,7 @@ func (self *SubmoduleCommands) Stash(submodule *models.SubmoduleConfig) error {
|
|||
}
|
||||
|
||||
cmdArgs := NewGitCmd("stash").
|
||||
RepoPath(submodule.Path).
|
||||
Dir(submodule.Path).
|
||||
Arg("--include-untracked").
|
||||
ToArgv()
|
||||
|
||||
|
|
|
@ -54,9 +54,9 @@ func (self *WorktreeCommands) Delete(worktreePath string, force bool) error {
|
|||
}
|
||||
|
||||
func (self *WorktreeCommands) Detach(worktreePath string) error {
|
||||
cmdArgs := NewGitCmd("checkout").Arg("--detach").ToArgv()
|
||||
cmdArgs := NewGitCmd("checkout").Arg("--detach").GitDir(filepath.Join(worktreePath, ".git")).ToArgv()
|
||||
|
||||
return self.cmd.New(cmdArgs).SetWd(worktreePath).Run()
|
||||
return self.cmd.New(cmdArgs).Run()
|
||||
}
|
||||
|
||||
func (self *WorktreeCommands) IsCurrentWorktree(path string) bool {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue