MCPcopy Create free account
hub / github.com/ejoffe/spr / GetLocalCommitStack

Function GetLocalCommitStack

git/helpers.go:51–75  ·  view source on GitHub ↗

GetLocalCommitStack returns a list of unmerged commits the list is ordered with the bottom commit in the stack first

(cfg *config.Config, gitcmd GitInterface)

Source from the content-addressed store, hash-verified

49//
50// the list is ordered with the bottom commit in the stack first
51func GetLocalCommitStack(cfg *config.Config, gitcmd GitInterface) []Commit {
52 var commitLog string
53 logCommand := fmt.Sprintf("log --format=medium --no-color %s/%s..HEAD",
54 cfg.Repo.GitHubRemote, cfg.Repo.GitHubBranch)
55 gitcmd.MustGit(logCommand, &commitLog)
56 commits, valid := parseLocalCommitStack(commitLog)
57 if !valid {
58 // if not valid - run rebase to add commit ids
59 rewordPath, err := exec.LookPath("spr_reword_helper")
60 check(err)
61 rebaseCommand := fmt.Sprintf("rebase %s/%s -i --autosquash --autostash",
62 cfg.Repo.GitHubRemote, cfg.Repo.GitHubBranch)
63 gitcmd.GitWithEditor(rebaseCommand, nil, rewordPath)
64
65 gitcmd.MustGit(logCommand, &commitLog)
66 commits, valid = parseLocalCommitStack(commitLog)
67 if !valid {
68 // if still not valid - panic
69 errMsg := "unable to fetch local commits\n"
70 errMsg += " most likely this is an issue with missing commit-id in the commit body\n"
71 panic(errMsg)
72 }
73 }
74 return commits
75}
76
77func parseLocalCommitStack(commitLog string) ([]Commit, bool) {
78 var commits []Commit

Callers 7

GetInfoMethod · 0.92
AmendCommitMethod · 0.92
EditCommitMethod · 0.92
UpdatePullRequestsMethod · 0.92
MergePullRequestsMethod · 0.92
RunMergeCheckMethod · 0.92
GetLocalTopCommitFunction · 0.85

Calls 4

parseLocalCommitStackFunction · 0.85
checkFunction · 0.70
MustGitMethod · 0.65
GitWithEditorMethod · 0.65

Tested by

no test coverage detected