git-town
git-town copied to clipboard
Aborting "set-parent-branch" causes next invocation of "set-parent-branch" to crash
Backstory (Feel free to skip)
I often forget that git town hack doesn't automatically select your current branch as the parent branch, but instead uses the main branch. I like this behavior, it's just that sometimes this isn't the behavior I wanted. Normally, I just run git town set-parent-branch, select the branch in the fancy selector and move on with my business. This time, however, my vim habits kicked in and I tried to use j to move the cursor. After getting the error message Use arrows to move, I instead opted to start over because my terminal was too small and the text was overflowing. This is how I found this bug.
Actual Bug Report
Run set-parent-branch and hit CTRL-C. There are 3 interesting things that will happen
git town set-parent-branchwill panic:
panic: interrupt
goroutine 1 [running]:
github.com/git-town/git-town/src/prompt.askForBranch(0xc000346b40, 0x6, 0x6, 0xc0001be0f0, 0x43, 0xc0001ca93a, 0x6, 0x5, 0x0)
/home/chris/github/git-town/git-town/src/prompt/branch_helpers.go:28 +0x186
github.com/git-town/git-town/src/prompt.AskForBranchParent(0xc0001339a0, 0x1c, 0xc0001ca93a, 0x6, 0xd6a820, 0x93abb6)
/home/chris/github/git-town/git-town/src/prompt/parent_branches.go:50 +0x275
github.com/git-town/git-town/src/prompt.AskForBranchAncestry(0xc0001339a0, 0x1c, 0xc0001ca93a, 0x6)
/home/chris/github/git-town/git-town/src/prompt/parent_branches.go:32 +0x31d
github.com/git-town/git-town/src/cmd.promptForParentBranch()
/home/chris/github/git-town/git-town/src/cmd/set_parent_branch.go:34 +0x329
github.com/git-town/git-town/src/cmd.glob..func47(0xd37600, 0xd697b0, 0x0, 0x0)
/home/chris/github/git-town/git-town/src/cmd/set_parent_branch.go:15 +0x20
github.com/spf13/cobra.(*Command).execute(0xd37600, 0xd697b0, 0x0, 0x0, 0xd37600, 0xd697b0)
/home/chris/github/git-town/git-town/vendor/github.com/spf13/cobra/command.go:846 +0x29d
github.com/spf13/cobra.(*Command).ExecuteC(0xd37360, 0x4436ba, 0xcf7a20, 0xc000000180)
/home/chris/github/git-town/git-town/vendor/github.com/spf13/cobra/command.go:950 +0x349
github.com/spf13/cobra.(*Command).Execute(...)
/home/chris/github/git-town/git-town/vendor/github.com/spf13/cobra/command.go:887
github.com/git-town/git-town/src/cmd.Execute()
/home/chris/github/git-town/git-town/src/cmd/root.go:31 +0x3d
main.main()
/home/chris/github/git-town/git-town/main.go:10 +0x20
- git-town config will no longer show your current branch
- calling
git town set-parent-branchagain will fail with the following error:
[chris-work:~/flowmill/flowmill/backend:(earth-build-api-docs[|]*)] git town set-parent-branch
Error running 'git config --unset git-town-branch.cgolden/earth-build-api-docs.parent' in "": exit status 5
Happily, running git town sync will bring the selector back and you can fix this. Just remember to use arrow keys, not home keys, this time.
p.s. Thanks again to kevgo for creating an invaluable tool that I use daily :)
Thanks for this bug report @cirego! As a friendly reminder reading your backstory, there are also the git town append and git town prepend commands, which create a new branch as a child or parent of the current branch. If these commands together with git hack don't cover your workflow, please let us know.
The panic is actually thrown by us in https://github.com/git-town/git-town/blob/master/src/prompt/branch_helpers.go#L28. This was originally a shortcut. Now that users run into this edge case, we should add better error handling:
- askForBranch should return a proper error instead of panicking when the user aborts
- make sure we leave the Git Town configuration in a consistent state in this situation
- alternatively to (2), rethink whether not being able to unset a Git Town configuration value is really a critical error condition
PS: I too miss using j or k whenever they are not available!
Thanks for this bug report @cirego! As a friendly reminder reading your backstory, there are also the
git town appendandgit town prependcommands, which create a new branch as a child or parent of the current branch. If these commands together withgit hackdon't cover your workflow, please let us know.The panic is actually thrown by us in https://github.com/git-town/git-town/blob/master/src/prompt/branch_helpers.go#L28. This was originally a shortcut. Now that users run into this edge case, we should add better error handling:
- askForBranch should return a proper error instead of panicking when the user aborts
- make sure we leave the Git Town configuration in a consistent state in this situation
- alternatively to (2), rethink whether not being able to unset a Git Town configuration value is really a critical error condition
PS: I too miss using
jorkwhenever they are not available!
Glad to hear you love j and k too! And normally, I usually remember to do append or prepend because they work exactly as I want them too. You really nailed the workflow there!
Btw, I ran into this symptom again, but via a different path:
git checkout -b some_branch
git town set-parent-branch
Running git town sync correctly asked for the parent branch and resolved the issue.
I cannot reproduce any of the reported issues anymore. I think the bugs causing this have been fixed in the meantime, for example as part of the engine overhaul in v10 and v11. Git Town is now a lot more robust than a couple of years ago. I'm therefore going to close this ticket. Please comment if you still encounter this issue with Git Town 11 and I'll reopen it.
In case you aren't aware, Git Town's new git town switch command allows changing branches using Vim motions like j and k. I hope you find this useful!