GetLocalCommitStack returns a list of unmerged commits the list is ordered with the bottom commit in the stack first
(cfg *config.Config, gitcmd GitInterface)
| 49 | // |
| 50 | // the list is ordered with the bottom commit in the stack first |
| 51 | func 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 | |
| 77 | func parseLocalCommitStack(commitLog string) ([]Commit, bool) { |
| 78 | var commits []Commit |
no test coverage detected