Repository navigation
fix(delete-squashed-branches): preserve default branch and target branch #1299
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
hyperupcall
merged 2 commits into
tj:main
from
musbabaff:fix/delete-squashed-branches-default-branch
Dec 3, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| # shellcheck shell=bash | ||
|
|
||
| source "$BATS_TEST_DIRNAME/test_util.sh" | ||
|
|
||
| setup_file() { | ||
| test_util.setup_file | ||
| test_util.install_command delete-squashed-branches | ||
| } | ||
|
|
||
| setup() { | ||
| test_util.cd_test | ||
|
|
||
| test_util.git_init | ||
| echo "base" > base.txt | ||
| git add base.txt | ||
| git commit -q -m "Initial commit" | ||
| } | ||
|
|
||
| @test "delete-squashed-branches deletes squash-merged branch and preserves default and unmerged branches" { | ||
| git checkout -q -b feat-squashed | ||
| echo "feat" > feat.txt | ||
| git add feat.txt | ||
| git commit -q -m "Feature commit" | ||
|
|
||
| git checkout -q main | ||
| git merge -q --squash feat-squashed | ||
| git commit -q -m "Squash feat-squashed" | ||
|
|
||
| git checkout -q -b feat-unmerged | ||
| echo "wip" > wip.txt | ||
| git add wip.txt | ||
| git commit -q -m "WIP commit" | ||
|
|
||
| git checkout -q main | ||
| run git delete-squashed-branches | ||
| assert_success | ||
|
|
||
| run git branch --list | ||
| assert_line -p "main" | ||
| assert_line -p "feat-unmerged" | ||
| refute_line -p "feat-squashed" | ||
| } | ||
|
|
||
| @test "delete-squashed-branches preserves main when main changes were squashed into another branch" { | ||
| git checkout -q -b release | ||
| echo "rel" > release.txt | ||
| git add release.txt | ||
| git commit -q -m "Release commit" | ||
|
|
||
| git checkout -q main | ||
| echo "fix" > hotfix.txt | ||
| git add hotfix.txt | ||
| git commit -q -m "Hotfix on main" | ||
|
|
||
| git checkout -q release | ||
| git merge -q --squash main | ||
| git commit -q -m "Squash main hotfix into release" | ||
|
|
||
| git checkout -q -b feat-squashed | ||
| echo "extra" > extra.txt | ||
| git add extra.txt | ||
| git commit -q -m "Extra commit" | ||
|
|
||
| git checkout -q release | ||
| git merge -q --squash feat-squashed | ||
| git commit -q -m "Squash feat-squashed into release" | ||
|
|
||
| run git delete-squashed-branches | ||
| assert_success | ||
|
|
||
| run git branch --list | ||
| assert_line -p "main" | ||
| assert_line -p "release" | ||
| refute_line -p "feat-squashed" | ||
| } | ||
|
|
||
| @test "delete-squashed-branches preserves custom init.defaultBranch and git-extras.default-branch" { | ||
| git branch -m main develop | ||
| git config init.defaultBranch develop | ||
|
|
||
| git checkout -q -b release | ||
| echo "rel" > release.txt | ||
| git add release.txt | ||
| git commit -q -m "Release commit" | ||
|
|
||
| git checkout -q develop | ||
| echo "dev" > dev.txt | ||
| git add dev.txt | ||
| git commit -q -m "Commit on develop" | ||
|
|
||
| git checkout -q release | ||
| git merge -q --squash develop | ||
| git commit -q -m "Squash develop into release" | ||
|
|
||
| run git delete-squashed-branches | ||
| assert_success | ||
|
|
||
| run git branch --list | ||
| assert_line -p "develop" | ||
| assert_line -p "release" | ||
|
|
||
| git branch -m develop primary | ||
| git config git-extras.default-branch primary | ||
|
|
||
| run git delete-squashed-branches release | ||
| assert_success | ||
|
|
||
| run git branch --list | ||
| assert_line -p "primary" | ||
| assert_line -p "release" | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.