mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-06-15 00:15:32 +02:00
Merge branch 'master' into hotfix/cursor-positioning
This commit is contained in:
@ -327,56 +327,50 @@ func (c *GitCommand) Push(branchName string, force bool) error {
|
||||
// retaining the message of the higher commit
|
||||
func (c *GitCommand) SquashPreviousTwoCommits(message string) error {
|
||||
// TODO: test this
|
||||
err := c.OSCommand.RunCommand("git reset --soft HEAD^")
|
||||
if err != nil {
|
||||
if err := c.OSCommand.RunCommand("git reset --soft HEAD^"); err != nil {
|
||||
return err
|
||||
}
|
||||
// TODO: if password is required, we need to return a subprocess
|
||||
return c.OSCommand.RunCommand("git commit --amend -m " + c.OSCommand.Quote(message))
|
||||
return c.OSCommand.RunCommand(fmt.Sprintf("git commit --amend -m %s", c.OSCommand.Quote(message)))
|
||||
}
|
||||
|
||||
// SquashFixupCommit squashes a 'FIXUP' commit into the commit beneath it,
|
||||
// retaining the commit message of the lower commit
|
||||
func (c *GitCommand) SquashFixupCommit(branchName string, shaValue string) error {
|
||||
var err error
|
||||
commands := []string{
|
||||
"git checkout -q " + shaValue,
|
||||
"git reset --soft " + shaValue + "^",
|
||||
"git commit --amend -C " + shaValue + "^",
|
||||
"git rebase --onto HEAD " + shaValue + " " + branchName,
|
||||
fmt.Sprintf("git checkout -q %s", shaValue),
|
||||
fmt.Sprintf("git reset --soft %s^", shaValue),
|
||||
fmt.Sprintf("git commit --amend -C %s^", shaValue),
|
||||
fmt.Sprintf("git rebase --onto HEAD %s %s", shaValue, branchName),
|
||||
}
|
||||
ret := ""
|
||||
for _, command := range commands {
|
||||
c.Log.Info(command)
|
||||
output, err := c.OSCommand.RunCommandWithOutput(command)
|
||||
ret += output
|
||||
if err != nil {
|
||||
|
||||
if output, err := c.OSCommand.RunCommandWithOutput(command); err != nil {
|
||||
ret := output
|
||||
// We are already in an error state here so we're just going to append
|
||||
// the output of these commands
|
||||
output, _ := c.OSCommand.RunCommandWithOutput(fmt.Sprintf("git branch -d %s", shaValue))
|
||||
ret += output
|
||||
output, _ = c.OSCommand.RunCommandWithOutput(fmt.Sprintf("git checkout %s", branchName))
|
||||
ret += output
|
||||
|
||||
c.Log.Info(ret)
|
||||
break
|
||||
return errors.New(ret)
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
// We are already in an error state here so we're just going to append
|
||||
// the output of these commands
|
||||
output, _ := c.OSCommand.RunCommandWithOutput("git branch -d " + shaValue)
|
||||
ret += output
|
||||
output, _ = c.OSCommand.RunCommandWithOutput("git checkout " + branchName)
|
||||
ret += output
|
||||
}
|
||||
if err != nil {
|
||||
return errors.New(ret)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// CatFile obtain the contents of a file
|
||||
// CatFile obtains the content of a file
|
||||
func (c *GitCommand) CatFile(fileName string) (string, error) {
|
||||
return c.OSCommand.RunCommandWithOutput("cat " + c.OSCommand.Quote(fileName))
|
||||
return c.OSCommand.RunCommandWithOutput(fmt.Sprintf("cat %s", c.OSCommand.Quote(fileName)))
|
||||
}
|
||||
|
||||
// StageFile stages a file
|
||||
func (c *GitCommand) StageFile(fileName string) error {
|
||||
return c.OSCommand.RunCommand("git add " + c.OSCommand.Quote(fileName))
|
||||
return c.OSCommand.RunCommand(fmt.Sprintf("git add %s", c.OSCommand.Quote(fileName)))
|
||||
}
|
||||
|
||||
// StageAll stages all files
|
||||
@ -391,13 +385,11 @@ func (c *GitCommand) UnstageAll() error {
|
||||
|
||||
// UnStageFile unstages a file
|
||||
func (c *GitCommand) UnStageFile(fileName string, tracked bool) error {
|
||||
var command string
|
||||
command := "git rm --cached %s"
|
||||
if tracked {
|
||||
command = "git reset HEAD "
|
||||
} else {
|
||||
command = "git rm --cached "
|
||||
command = "git reset HEAD %s"
|
||||
}
|
||||
return c.OSCommand.RunCommand(command + c.OSCommand.Quote(fileName))
|
||||
return c.OSCommand.RunCommand(fmt.Sprintf(command, c.OSCommand.Quote(fileName)))
|
||||
}
|
||||
|
||||
// GitStatus returns the plaintext short status of the repo
|
||||
|
Reference in New Issue
Block a user