fix(branch): prevent git delete-merged-branches from deleting default branch (#1132) - #1269
fix(branch): prevent git delete-merged-branches from deleting default branch (#1132)#1269vaibhavmashal wants to merge 3 commits into
Conversation
|
Woah this diff is huge, perhaps there was a mistake in the history of the branch of this PR? |
b323130 to
d0ca537
Compare
|
Good catch @hyperupcall! My initial branch history had diverged from upstream. I've rebased directly onto \upstream/master\ — the PR diff is now clean with just the intended fix (+14 / -4 across \git-delete-merged-branches, \git-show-merged-branches, \git-show-unmerged-branches, and \git-extra-utility). |
spacewander
left a comment
There was a problem hiding this comment.
Let's add test in https://github.com/tj/git-extras/tree/main/tests to cover the change
| init_default_branch=$(git config --get init.defaultBranch) | ||
| if [ -n "$extras_default_branch" ]; then | ||
| echo "$extras_default_branch" | ||
| elif [ -n "$origin_head" ]; then |
There was a problem hiding this comment.
This hurts repo uses own or other remote names. We should append it after the existing init_default_branch branch.
|
|
||
| git branch --no-color --merged | grep -v "\*" | grep -v "$(git_extra_default_branch)" | tr -d ' ' | ||
| default_branch=$(git_extra_default_branch) | ||
| git branch --no-color --merged | grep -v "\*" | tr -d ' ' | grep -vE "^(${default_branch}|main|master|trunk|svn)$" |
There was a problem hiding this comment.
Maybe we should use Igrep -Fvx with separate -e arguments to avoid regex char in the branch name, like release/foo+bar
|
Added unit tests in \ ests/test_delete_merged_branches.py\ to cover \git delete-merged-branches, \git show-merged-branches, and \git show-unmerged-branches. The tests verify that:
Pushed in commit \ca67303. |
08ff251 to
7eb6eed
Compare
|
Hi @spacewander, Thank you for the review and suggestions! I have addressed all the feedback in commit
|
Summary
Fixes #1132
When running \git delete-merged-branches\ on a repository where the default/primary branch is \master\ (or when \origin/HEAD\ is set) from a non-default branch, \git_extra_default_branch\ previously fell back to \main\ (or whatever \init.defaultBranch\ was set to globally), which resulted in \master\ being treated as a merged branch and deleted.
Changes
efs/remotes/origin/HEAD\ symbolic ref