Skip to content

Commit 396215a

Browse files
committed
Extract helper function for getting the hash of the last commit made
1 parent 42c157a commit 396215a

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

pkg/commands/git_commands/rebase.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,11 @@ func (self *RebaseCommands) GitRebaseEditTodo(todosFileContent []byte) error {
284284
return cmdObj.Run()
285285
}
286286

287+
func (self *RebaseCommands) getHashOfLastCommitMade() (string, error) {
288+
cmdArgs := NewGitCmd("rev-parse").Arg("--verify", "HEAD").ToArgv()
289+
return self.cmd.New(cmdArgs).RunWithOutput()
290+
}
291+
287292
// AmendTo amends the given commit with whatever files are staged
288293
func (self *RebaseCommands) AmendTo(commits []*models.Commit, commitIndex int) error {
289294
commit := commits[commitIndex]
@@ -292,9 +297,7 @@ func (self *RebaseCommands) AmendTo(commits []*models.Commit, commitIndex int) e
292297
return err
293298
}
294299

295-
// Get the hash of the commit we just created
296-
cmdArgs := NewGitCmd("rev-parse").Arg("--verify", "HEAD").ToArgv()
297-
fixupHash, err := self.cmd.New(cmdArgs).RunWithOutput()
300+
fixupHash, err := self.getHashOfLastCommitMade()
298301
if err != nil {
299302
return err
300303
}

0 commit comments

Comments
 (0)