Skip to content

Commit e00d2bc

Browse files
committed
Don't require that a branch is checked out to rebase
1 parent 4087dca commit e00d2bc

File tree

4 files changed

+48
-2
lines changed

4 files changed

+48
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ pull-request-parser uses the Github API to parse open pull requests and aggregat
22

33
### Setup
44
```sh
5-
go get github.com/guywithnose/pull-request-parser/prp
5+
go get github.com/guywithnose/pull-request-parser/cmd/prp
66
prp --config ~/prpConfig.json init-config
77
prp --config ~/prpConfig.json profile add default --token {YOUR_GITHUB_TOKEN}
88
prp --config ~/prpConfig.json repo add {USER} {REPO_NAME}
File renamed without changes.

command/autoRebase_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,46 @@ func TestCmdAutoRebase(t *testing.T) {
396396
runner.NewExpectedCommand(repoDir, "git fetch upstream", "", 0),
397397
runner.NewExpectedCommand(repoDir, "git stash", "", 0),
398398
runner.NewExpectedCommand(repoDir, "git symbolic-ref HEAD", "Not a branch", 128),
399+
runner.NewExpectedCommand(repoDir, "git rev-parse HEAD", "abcdefg", 0),
400+
runner.NewExpectedCommand(repoDir, "git checkout -b prp-ref1", "", 0),
401+
runner.NewExpectedCommand(repoDir, "git reset --hard origin/ref1", "", 0),
402+
runner.NewExpectedCommand(repoDir, "git rebase upstream/baseRef1", "", 0),
403+
runner.NewExpectedCommand(repoDir, "git push origin prp-ref1:ref1 --force", "", 0),
404+
runner.NewExpectedCommand(repoDir, "git checkout abcdefg", "", 0),
405+
runner.NewExpectedCommand(repoDir, "git branch -D prp-ref1", "", 0),
406+
runner.NewExpectedCommand(repoDir, "git stash pop", "", 0),
407+
},
408+
[]string{
409+
"Requesting repo data from config",
410+
"Analyzing remotes",
411+
"Checking for local changes",
412+
"Fetching from remote: origin",
413+
"Fetching from remote: upstream",
414+
"Local changes found... stashing",
415+
"Saving current branch name",
416+
"Current branch name is abcdefg",
417+
"Checking out temporary branch: prp-ref1",
418+
"Resetting code to origin/ref1",
419+
"Rebasing against upstream/baseRef1",
420+
"Pushing to origin/ref1",
421+
"Going back to branch abcdefg",
422+
"Deleting temporary branch prp-ref1",
423+
"Popping the stash",
424+
"",
425+
},
426+
true,
427+
false,
428+
},
429+
{
430+
"NoValidHead",
431+
[]*runner.ExpectedCommand{
432+
runner.NewExpectedCommand(repoDir, "git remote -v", "origin\tlabelSSHURL (push)\nupstream\tbaseLabel1SSHURL (fetch)", 0),
433+
runner.NewExpectedCommand(repoDir, "git diff-index --quiet HEAD", "", 1),
434+
runner.NewExpectedCommand(repoDir, "git fetch origin", "", 0),
435+
runner.NewExpectedCommand(repoDir, "git fetch upstream", "", 0),
436+
runner.NewExpectedCommand(repoDir, "git stash", "", 0),
437+
runner.NewExpectedCommand(repoDir, "git symbolic-ref HEAD", "Not a branch", 128),
438+
runner.NewExpectedCommand(repoDir, "git rev-parse HEAD", "Not a branch", 128),
399439
runner.NewExpectedCommand(repoDir, "git stash pop", "", 0),
400440
},
401441
[]string{

command/rebaser.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,13 @@ func (r rebaser) getCurrentBranch(path string) (string, error) {
207207
if err != nil {
208208
code := getErrorCode(err)
209209
if code == 128 {
210-
return "", fmt.Errorf("No branch checked out in %s\n%s", path, string(currentBranchOutput))
210+
getCurrentBranch = r.cmdWrapper.New(path, "git", "rev-parse", "HEAD")
211+
currentBranchOutput, err = getCurrentBranch.CombinedOutput()
212+
if err != nil {
213+
return "", fmt.Errorf("No branch checked out in %s\n%s", path, string(currentBranchOutput))
214+
}
215+
216+
return strings.Replace(strings.Replace(string(currentBranchOutput), "refs/heads/", "", -1), "\n", "", -1), nil
211217
}
212218

213219
return "", fmt.Errorf("%s\n%s", err, string(currentBranchOutput))

0 commit comments

Comments
 (0)