mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-11 04:15:48 +02:00
Skip post-checkout hook when discarding changes
Some people have post-checkout hooks that take a lot of time, which makes discarding changes slow. You can argue that a post-checkout hook should only run when you switch branches, so it doesnt't have to run when checking out single files or directories. You can also argue that lazygit might have implemented discarding changes by taking the current patch and applying it in reverse, which wouldn't have run a post-checkout hook either. So disable them for all cases where we use git checkout with a path; this includes checking out a file from the commit files view.
This commit is contained in:
parent
56695078c3
commit
964278255b
3 changed files with 22 additions and 14 deletions
|
@ -109,6 +109,10 @@ func (self *WorkingTreeCommands) BeforeAndAfterFileForRename(file *models.File)
|
|||
return beforeFile, afterFile, nil
|
||||
}
|
||||
|
||||
func newCheckoutCommand() *GitCommandBuilder {
|
||||
return NewGitCmd("checkout").Config(fmt.Sprintf("core.hooksPath=%s", os.DevNull))
|
||||
}
|
||||
|
||||
// DiscardAllFileChanges directly
|
||||
func (self *WorkingTreeCommands) DiscardAllFileChanges(file *models.File) error {
|
||||
if file.IsRename() {
|
||||
|
@ -130,7 +134,7 @@ func (self *WorkingTreeCommands) DiscardAllFileChanges(file *models.File) error
|
|||
|
||||
if file.ShortStatus == "AA" {
|
||||
if err := self.cmd.New(
|
||||
NewGitCmd("checkout").Arg("--ours", "--", file.Name).ToArgv(),
|
||||
newCheckoutCommand().Arg("--ours", "--", file.Name).ToArgv(),
|
||||
).Run(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -189,7 +193,7 @@ func (self *WorkingTreeCommands) DiscardUnstagedDirChanges(node IFileNode) error
|
|||
return err
|
||||
}
|
||||
|
||||
cmdArgs := NewGitCmd("checkout").Arg("--", node.GetPath()).ToArgv()
|
||||
cmdArgs := newCheckoutCommand().Arg("--", node.GetPath()).ToArgv()
|
||||
if err := self.cmd.New(cmdArgs).Run(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -222,7 +226,7 @@ func (self *WorkingTreeCommands) RemoveUntrackedDirFiles(node IFileNode) error {
|
|||
}
|
||||
|
||||
func (self *WorkingTreeCommands) DiscardUnstagedFileChanges(file *models.File) error {
|
||||
cmdArgs := NewGitCmd("checkout").Arg("--", file.Name).ToArgv()
|
||||
cmdArgs := newCheckoutCommand().Arg("--", file.Name).ToArgv()
|
||||
return self.cmd.New(cmdArgs).Run()
|
||||
}
|
||||
|
||||
|
@ -315,7 +319,7 @@ func (self *WorkingTreeCommands) ShowFileDiffCmdObj(from string, to string, reve
|
|||
|
||||
// CheckoutFile checks out the file for the given commit
|
||||
func (self *WorkingTreeCommands) CheckoutFile(commitHash, fileName string) error {
|
||||
cmdArgs := NewGitCmd("checkout").Arg(commitHash, "--", fileName).
|
||||
cmdArgs := newCheckoutCommand().Arg(commitHash, "--", fileName).
|
||||
ToArgv()
|
||||
|
||||
return self.cmd.New(cmdArgs).Run()
|
||||
|
@ -323,7 +327,7 @@ func (self *WorkingTreeCommands) CheckoutFile(commitHash, fileName string) error
|
|||
|
||||
// DiscardAnyUnstagedFileChanges discards any unstaged file changes via `git checkout -- .`
|
||||
func (self *WorkingTreeCommands) DiscardAnyUnstagedFileChanges() error {
|
||||
cmdArgs := NewGitCmd("checkout").Arg("--", ".").
|
||||
cmdArgs := newCheckoutCommand().Arg("--", ".").
|
||||
ToArgv()
|
||||
|
||||
return self.cmd.New(cmdArgs).Run()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue