2022-01-08 05:00:36 +02:00
|
|
|
package git_commands
|
2022-01-02 01:34:33 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/go-errors/errors"
|
|
|
|
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
|
|
|
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
|
|
|
)
|
|
|
|
|
|
|
|
type WorkingTreeCommands struct {
|
2022-01-18 12:26:21 +02:00
|
|
|
*GitCommon
|
2022-01-02 01:34:33 +02:00
|
|
|
submodule *SubmoduleCommands
|
2022-11-11 04:19:29 +02:00
|
|
|
fileLoader *FileLoader
|
2022-01-02 01:34:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewWorkingTreeCommands(
|
2022-01-18 12:26:21 +02:00
|
|
|
gitCommon *GitCommon,
|
|
|
|
submodule *SubmoduleCommands,
|
2022-11-11 04:19:29 +02:00
|
|
|
fileLoader *FileLoader,
|
2022-01-02 01:34:33 +02:00
|
|
|
) *WorkingTreeCommands {
|
|
|
|
return &WorkingTreeCommands{
|
2022-01-18 12:26:21 +02:00
|
|
|
GitCommon: gitCommon,
|
|
|
|
submodule: submodule,
|
2022-01-02 01:34:33 +02:00
|
|
|
fileLoader: fileLoader,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (self *WorkingTreeCommands) OpenMergeToolCmdObj() oscommands.ICmdObj {
|
2023-05-21 09:00:29 +02:00
|
|
|
return self.cmd.New(NewGitCmd("mergetool").ToArgv())
|
2022-01-02 01:34:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (self *WorkingTreeCommands) OpenMergeTool() error {
|
|
|
|
return self.OpenMergeToolCmdObj().Run()
|
|
|
|
}
|
|
|
|
|
|
|
|
// StageFile stages a file
|
2022-01-25 16:20:19 +02:00
|
|
|
func (self *WorkingTreeCommands) StageFile(path string) error {
|
|
|
|
return self.StageFiles([]string{path})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (self *WorkingTreeCommands) StageFiles(paths []string) error {
|
2023-05-21 09:00:29 +02:00
|
|
|
cmdArgs := NewGitCmd("add").Arg("--").Arg(paths...).ToArgv()
|
2023-05-19 12:18:02 +02:00
|
|
|
|
2023-05-21 09:00:29 +02:00
|
|
|
return self.cmd.New(cmdArgs).Run()
|
2022-01-02 01:34:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// StageAll stages all files
|
|
|
|
func (self *WorkingTreeCommands) StageAll() error {
|
2023-05-21 09:00:29 +02:00
|
|
|
cmdArgs := NewGitCmd("add").Arg("-A").ToArgv()
|
2023-05-19 12:18:02 +02:00
|
|
|
|
2023-05-21 09:00:29 +02:00
|
|
|
return self.cmd.New(cmdArgs).Run()
|
2022-01-02 01:34:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// UnstageAll unstages all files
|
|
|
|
func (self *WorkingTreeCommands) UnstageAll() error {
|
2023-05-21 09:00:29 +02:00
|
|
|
return self.cmd.New(NewGitCmd("reset").ToArgv()).Run()
|
2022-01-02 01:34:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// UnStageFile unstages a file
|
|
|
|
// we accept an array of filenames for the cases where a file has been renamed i.e.
|
|
|
|
// we accept the current name and the previous name
|
|
|
|
func (self *WorkingTreeCommands) UnStageFile(fileNames []string, reset bool) error {
|
|
|
|
for _, name := range fileNames {
|
2023-05-21 09:00:29 +02:00
|
|
|
var cmdArgs []string
|
2023-05-19 12:18:02 +02:00
|
|
|
if reset {
|
2023-05-21 09:00:29 +02:00
|
|
|
cmdArgs = NewGitCmd("reset").Arg("HEAD", "--", name).ToArgv()
|
2023-05-19 12:18:02 +02:00
|
|
|
} else {
|
2023-05-21 09:00:29 +02:00
|
|
|
cmdArgs = NewGitCmd("rm").Arg("--cached", "--force", "--", name).ToArgv()
|
2023-05-19 12:18:02 +02:00
|
|
|
}
|
|
|
|
|
2023-05-21 09:00:29 +02:00
|
|
|
err := self.cmd.New(cmdArgs).Run()
|
2022-01-02 01:34:33 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-01-08 05:00:36 +02:00
|
|
|
func (self *WorkingTreeCommands) BeforeAndAfterFileForRename(file *models.File) (*models.File, *models.File, error) {
|
2022-01-02 01:34:33 +02:00
|
|
|
if !file.IsRename() {
|
|
|
|
return nil, nil, errors.New("Expected renamed file")
|
|
|
|
}
|
|
|
|
|
|
|
|
// we've got a file that represents a rename from one file to another. Here we will refetch
|
|
|
|
// all files, passing the --no-renames flag and then recursively call the function
|
|
|
|
// again for the before file and after file.
|
|
|
|
|
2022-11-11 04:19:29 +02:00
|
|
|
filesWithoutRenames := self.fileLoader.GetStatusFiles(GetStatusFileOptions{NoRenames: true})
|
2022-01-02 01:34:33 +02:00
|
|
|
|
|
|
|
var beforeFile *models.File
|
|
|
|
var afterFile *models.File
|
|
|
|
for _, f := range filesWithoutRenames {
|
|
|
|
if f.Name == file.PreviousName {
|
|
|
|
beforeFile = f
|
|
|
|
}
|
|
|
|
|
|
|
|
if f.Name == file.Name {
|
|
|
|
afterFile = f
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if beforeFile == nil || afterFile == nil {
|
|
|
|
return nil, nil, errors.New("Could not find deleted file or new file for file rename")
|
|
|
|
}
|
|
|
|
|
|
|
|
if beforeFile.IsRename() || afterFile.IsRename() {
|
|
|
|
// probably won't happen but we want to ensure we don't get an infinite loop
|
|
|
|
return nil, nil, errors.New("Nested rename found")
|
|
|
|
}
|
|
|
|
|
|
|
|
return beforeFile, afterFile, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// DiscardAllFileChanges directly
|
2022-01-08 05:00:36 +02:00
|
|
|
func (self *WorkingTreeCommands) DiscardAllFileChanges(file *models.File) error {
|
2022-01-02 01:34:33 +02:00
|
|
|
if file.IsRename() {
|
2022-01-08 05:00:36 +02:00
|
|
|
beforeFile, afterFile, err := self.BeforeAndAfterFileForRename(file)
|
2022-01-02 01:34:33 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-01-08 05:00:36 +02:00
|
|
|
if err := self.DiscardAllFileChanges(beforeFile); err != nil {
|
2022-01-02 01:34:33 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-01-08 05:00:36 +02:00
|
|
|
if err := self.DiscardAllFileChanges(afterFile); err != nil {
|
2022-01-02 01:34:33 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if file.ShortStatus == "AA" {
|
2023-05-19 12:18:02 +02:00
|
|
|
if err := self.cmd.New(
|
2023-05-21 09:00:29 +02:00
|
|
|
NewGitCmd("checkout").Arg("--ours", "--", file.Name).ToArgv(),
|
2023-05-19 12:18:02 +02:00
|
|
|
).Run(); err != nil {
|
2022-01-02 01:34:33 +02:00
|
|
|
return err
|
|
|
|
}
|
2023-05-19 12:18:02 +02:00
|
|
|
|
|
|
|
if err := self.cmd.New(
|
2023-05-21 09:00:29 +02:00
|
|
|
NewGitCmd("add").Arg("--", file.Name).ToArgv(),
|
2023-05-19 12:18:02 +02:00
|
|
|
).Run(); err != nil {
|
2022-01-02 01:34:33 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if file.ShortStatus == "DU" {
|
2023-05-19 12:18:02 +02:00
|
|
|
return self.cmd.New(
|
2023-05-23 11:58:09 +02:00
|
|
|
NewGitCmd("rm").Arg("--", file.Name).ToArgv(),
|
2023-05-19 12:18:02 +02:00
|
|
|
).Run()
|
2022-01-02 01:34:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// if the file isn't tracked, we assume you want to delete it
|
|
|
|
if file.HasStagedChanges || file.HasMergeConflicts {
|
2023-05-19 12:18:02 +02:00
|
|
|
if err := self.cmd.New(
|
2023-05-21 09:00:29 +02:00
|
|
|
NewGitCmd("reset").Arg("--", file.Name).ToArgv(),
|
2023-05-19 12:18:02 +02:00
|
|
|
).Run(); err != nil {
|
2022-01-02 01:34:33 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if file.ShortStatus == "DD" || file.ShortStatus == "AU" {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if file.Added {
|
2022-01-08 05:00:36 +02:00
|
|
|
return self.os.RemoveFile(file.Name)
|
2022-01-02 01:34:33 +02:00
|
|
|
}
|
2022-01-08 05:00:36 +02:00
|
|
|
return self.DiscardUnstagedFileChanges(file)
|
2022-01-02 01:34:33 +02:00
|
|
|
}
|
|
|
|
|
2022-01-21 15:13:51 +02:00
|
|
|
type IFileNode interface {
|
|
|
|
ForEachFile(cb func(*models.File) error) error
|
|
|
|
GetFilePathsMatching(test func(*models.File) bool) []string
|
|
|
|
GetPath() string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (self *WorkingTreeCommands) DiscardAllDirChanges(node IFileNode) error {
|
2022-01-02 01:34:33 +02:00
|
|
|
// this could be more efficient but we would need to handle all the edge cases
|
2022-01-08 05:00:36 +02:00
|
|
|
return node.ForEachFile(self.DiscardAllFileChanges)
|
2022-01-02 01:34:33 +02:00
|
|
|
}
|
|
|
|
|
2022-01-21 15:13:51 +02:00
|
|
|
func (self *WorkingTreeCommands) DiscardUnstagedDirChanges(node IFileNode) error {
|
2022-01-08 05:00:36 +02:00
|
|
|
if err := self.RemoveUntrackedDirFiles(node); err != nil {
|
2022-01-02 01:34:33 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-05-21 09:00:29 +02:00
|
|
|
cmdArgs := NewGitCmd("checkout").Arg("--", node.GetPath()).ToArgv()
|
|
|
|
if err := self.cmd.New(cmdArgs).Run(); err != nil {
|
2022-01-02 01:34:33 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-01-21 15:13:51 +02:00
|
|
|
func (self *WorkingTreeCommands) RemoveUntrackedDirFiles(node IFileNode) error {
|
|
|
|
untrackedFilePaths := node.GetFilePathsMatching(
|
|
|
|
func(file *models.File) bool { return !file.GetIsTracked() },
|
2022-01-02 01:34:33 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
for _, path := range untrackedFilePaths {
|
|
|
|
err := os.Remove(path)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// DiscardUnstagedFileChanges directly
|
2022-01-08 05:00:36 +02:00
|
|
|
func (self *WorkingTreeCommands) DiscardUnstagedFileChanges(file *models.File) error {
|
2023-05-21 09:00:29 +02:00
|
|
|
cmdArgs := NewGitCmd("checkout").Arg("--", file.Name).ToArgv()
|
|
|
|
return self.cmd.New(cmdArgs).Run()
|
2022-01-02 01:34:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Ignore adds a file to the gitignore for the repo
|
2022-01-08 05:00:36 +02:00
|
|
|
func (self *WorkingTreeCommands) Ignore(filename string) error {
|
|
|
|
return self.os.AppendLineToFile(".gitignore", filename)
|
2022-01-02 01:34:33 +02:00
|
|
|
}
|
|
|
|
|
2022-06-24 23:10:13 +02:00
|
|
|
// Exclude adds a file to the .git/info/exclude for the repo
|
|
|
|
func (self *WorkingTreeCommands) Exclude(filename string) error {
|
|
|
|
return self.os.AppendLineToFile(".git/info/exclude", filename)
|
|
|
|
}
|
|
|
|
|
2022-01-02 01:34:33 +02:00
|
|
|
// WorktreeFileDiff returns the diff of a file
|
2023-08-28 12:39:52 +02:00
|
|
|
func (self *WorkingTreeCommands) WorktreeFileDiff(file *models.File, plain bool, cached bool) string {
|
2022-01-02 01:34:33 +02:00
|
|
|
// for now we assume an error means the file was deleted
|
2023-08-28 12:39:52 +02:00
|
|
|
s, _ := self.WorktreeFileDiffCmdObj(file, plain, cached).RunWithOutput()
|
2022-01-02 01:34:33 +02:00
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
2023-08-28 12:39:52 +02:00
|
|
|
func (self *WorkingTreeCommands) WorktreeFileDiffCmdObj(node models.IFile, plain bool, cached bool) oscommands.ICmdObj {
|
2022-01-08 05:00:36 +02:00
|
|
|
colorArg := self.UserConfig.Git.Paging.ColorArg
|
2022-01-02 01:34:33 +02:00
|
|
|
if plain {
|
|
|
|
colorArg = "never"
|
|
|
|
}
|
|
|
|
|
2023-08-28 13:09:55 +02:00
|
|
|
contextSize := self.AppState.DiffContextSize
|
2023-05-19 12:18:02 +02:00
|
|
|
prevPath := node.GetPreviousPath()
|
|
|
|
noIndex := !node.GetIsTracked() && !node.GetHasStagedChanges() && !cached && node.GetIsFile()
|
2023-06-30 08:42:39 +02:00
|
|
|
extDiffCmd := self.UserConfig.Git.Paging.ExternalDiffCommand
|
|
|
|
useExtDiff := extDiffCmd != "" && !plain
|
2023-05-19 12:18:02 +02:00
|
|
|
|
2023-05-21 09:00:29 +02:00
|
|
|
cmdArgs := NewGitCmd("diff").
|
2023-06-30 08:42:39 +02:00
|
|
|
ConfigIf(useExtDiff, "diff.external="+extDiffCmd).
|
|
|
|
ArgIfElse(useExtDiff, "--ext-diff", "--no-ext-diff").
|
2023-05-19 12:18:02 +02:00
|
|
|
Arg("--submodule").
|
|
|
|
Arg(fmt.Sprintf("--unified=%d", contextSize)).
|
|
|
|
Arg(fmt.Sprintf("--color=%s", colorArg)).
|
2023-08-28 12:39:52 +02:00
|
|
|
ArgIf(!plain && self.AppState.IgnoreWhitespaceInDiffView, "--ignore-all-space").
|
2023-05-19 12:18:02 +02:00
|
|
|
ArgIf(cached, "--cached").
|
|
|
|
ArgIf(noIndex, "--no-index").
|
|
|
|
Arg("--").
|
|
|
|
ArgIf(noIndex, "/dev/null").
|
2023-05-21 09:00:29 +02:00
|
|
|
Arg(node.GetPath()).
|
|
|
|
ArgIf(prevPath != "", prevPath).
|
|
|
|
ToArgv()
|
2022-01-02 01:34:33 +02:00
|
|
|
|
2023-05-21 09:00:29 +02:00
|
|
|
return self.cmd.New(cmdArgs).DontLog()
|
2022-01-02 01:34:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ShowFileDiff get the diff of specified from and to. Typically this will be used for a single commit so it'll be 123abc^..123abc
|
|
|
|
// but when we're in diff mode it could be any 'from' to any 'to'. The reverse flag is also here thanks to diff mode.
|
2023-08-28 12:39:52 +02:00
|
|
|
func (self *WorkingTreeCommands) ShowFileDiff(from string, to string, reverse bool, fileName string, plain bool) (string, error) {
|
|
|
|
return self.ShowFileDiffCmdObj(from, to, reverse, fileName, plain).RunWithOutput()
|
2022-01-02 01:34:33 +02:00
|
|
|
}
|
|
|
|
|
2023-08-28 12:39:52 +02:00
|
|
|
func (self *WorkingTreeCommands) ShowFileDiffCmdObj(from string, to string, reverse bool, fileName string, plain bool) oscommands.ICmdObj {
|
2023-08-28 13:09:55 +02:00
|
|
|
contextSize := self.AppState.DiffContextSize
|
2023-05-19 12:18:02 +02:00
|
|
|
|
|
|
|
colorArg := self.UserConfig.Git.Paging.ColorArg
|
2022-01-02 01:34:33 +02:00
|
|
|
if plain {
|
|
|
|
colorArg = "never"
|
|
|
|
}
|
|
|
|
|
2023-06-30 08:42:39 +02:00
|
|
|
extDiffCmd := self.UserConfig.Git.Paging.ExternalDiffCommand
|
|
|
|
useExtDiff := extDiffCmd != "" && !plain
|
|
|
|
|
2023-05-21 09:00:29 +02:00
|
|
|
cmdArgs := NewGitCmd("diff").
|
2023-06-30 08:42:39 +02:00
|
|
|
ConfigIf(useExtDiff, "diff.external="+extDiffCmd).
|
|
|
|
ArgIfElse(useExtDiff, "--ext-diff", "--no-ext-diff").
|
2023-05-19 12:18:02 +02:00
|
|
|
Arg("--submodule").
|
|
|
|
Arg(fmt.Sprintf("--unified=%d", contextSize)).
|
|
|
|
Arg("--no-renames").
|
|
|
|
Arg(fmt.Sprintf("--color=%s", colorArg)).
|
|
|
|
Arg(from).
|
|
|
|
Arg(to).
|
|
|
|
ArgIf(reverse, "-R").
|
2023-08-28 12:39:52 +02:00
|
|
|
ArgIf(!plain && self.AppState.IgnoreWhitespaceInDiffView, "--ignore-all-space").
|
2023-05-19 12:18:02 +02:00
|
|
|
Arg("--").
|
2023-05-21 09:00:29 +02:00
|
|
|
Arg(fileName).
|
|
|
|
ToArgv()
|
2023-02-03 21:20:20 +02:00
|
|
|
|
2023-05-21 09:00:29 +02:00
|
|
|
return self.cmd.New(cmdArgs).DontLog()
|
2022-01-02 01:34:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// CheckoutFile checks out the file for the given commit
|
2022-01-08 05:00:36 +02:00
|
|
|
func (self *WorkingTreeCommands) CheckoutFile(commitSha, fileName string) error {
|
2023-05-21 09:00:29 +02:00
|
|
|
cmdArgs := NewGitCmd("checkout").Arg(commitSha, "--", fileName).
|
|
|
|
ToArgv()
|
2023-05-19 12:18:02 +02:00
|
|
|
|
2023-05-21 09:00:29 +02:00
|
|
|
return self.cmd.New(cmdArgs).Run()
|
2022-01-02 01:34:33 +02:00
|
|
|
}
|
|
|
|
|
2023-05-19 12:18:02 +02:00
|
|
|
// DiscardAnyUnstagedFileChanges discards any unstaged file changes via `git checkout -- .`
|
2022-01-08 05:00:36 +02:00
|
|
|
func (self *WorkingTreeCommands) DiscardAnyUnstagedFileChanges() error {
|
2023-05-21 09:00:29 +02:00
|
|
|
cmdArgs := NewGitCmd("checkout").Arg("--", ".").
|
|
|
|
ToArgv()
|
2023-05-19 12:18:02 +02:00
|
|
|
|
2023-05-21 09:00:29 +02:00
|
|
|
return self.cmd.New(cmdArgs).Run()
|
2022-01-02 01:34:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// RemoveTrackedFiles will delete the given file(s) even if they are currently tracked
|
2022-01-08 05:00:36 +02:00
|
|
|
func (self *WorkingTreeCommands) RemoveTrackedFiles(name string) error {
|
2023-05-21 09:00:29 +02:00
|
|
|
cmdArgs := NewGitCmd("rm").Arg("-r", "--cached", "--", name).
|
|
|
|
ToArgv()
|
2023-05-19 12:18:02 +02:00
|
|
|
|
2023-05-21 09:00:29 +02:00
|
|
|
return self.cmd.New(cmdArgs).Run()
|
2022-01-02 01:34:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// RemoveUntrackedFiles runs `git clean -fd`
|
2022-01-08 05:00:36 +02:00
|
|
|
func (self *WorkingTreeCommands) RemoveUntrackedFiles() error {
|
2023-05-21 09:00:29 +02:00
|
|
|
cmdArgs := NewGitCmd("clean").Arg("-fd").ToArgv()
|
2023-05-19 12:18:02 +02:00
|
|
|
|
2023-05-21 09:00:29 +02:00
|
|
|
return self.cmd.New(cmdArgs).Run()
|
2022-01-02 01:34:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ResetAndClean removes all unstaged changes and removes all untracked files
|
2022-01-08 05:00:36 +02:00
|
|
|
func (self *WorkingTreeCommands) ResetAndClean() error {
|
|
|
|
submoduleConfigs, err := self.submodule.GetConfigs()
|
2022-01-02 01:34:33 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(submoduleConfigs) > 0 {
|
2022-01-08 05:00:36 +02:00
|
|
|
if err := self.submodule.ResetSubmodules(submoduleConfigs); err != nil {
|
2022-01-02 01:34:33 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-08 05:00:36 +02:00
|
|
|
if err := self.ResetHard("HEAD"); err != nil {
|
2022-01-02 01:34:33 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-01-08 05:00:36 +02:00
|
|
|
return self.RemoveUntrackedFiles()
|
2022-01-02 01:34:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ResetHardHead runs `git reset --hard`
|
|
|
|
func (self *WorkingTreeCommands) ResetHard(ref string) error {
|
2023-05-21 09:00:29 +02:00
|
|
|
cmdArgs := NewGitCmd("reset").Arg("--hard", ref).
|
|
|
|
ToArgv()
|
2023-05-19 12:18:02 +02:00
|
|
|
|
2023-05-21 09:00:29 +02:00
|
|
|
return self.cmd.New(cmdArgs).Run()
|
2022-01-02 01:34:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ResetSoft runs `git reset --soft HEAD`
|
|
|
|
func (self *WorkingTreeCommands) ResetSoft(ref string) error {
|
2023-05-21 09:00:29 +02:00
|
|
|
cmdArgs := NewGitCmd("reset").Arg("--soft", ref).
|
|
|
|
ToArgv()
|
2022-01-02 01:34:33 +02:00
|
|
|
|
2023-05-21 09:00:29 +02:00
|
|
|
return self.cmd.New(cmdArgs).Run()
|
2022-01-02 01:34:33 +02:00
|
|
|
}
|
2022-01-08 07:02:56 +02:00
|
|
|
|
2023-05-19 12:18:02 +02:00
|
|
|
func (self *WorkingTreeCommands) ResetMixed(ref string) error {
|
2023-05-21 09:00:29 +02:00
|
|
|
cmdArgs := NewGitCmd("reset").Arg("--mixed", ref).
|
|
|
|
ToArgv()
|
2022-01-08 07:02:56 +02:00
|
|
|
|
2023-05-21 09:00:29 +02:00
|
|
|
return self.cmd.New(cmdArgs).Run()
|
2022-01-08 07:02:56 +02:00
|
|
|
}
|