summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xgit-rewrite-branch16
1 files changed, 10 insertions, 6 deletions
diff --git a/git-rewrite-branch b/git-rewrite-branch
index a2b3c81..c9838cf 100755
--- a/git-rewrite-branch
+++ b/git-rewrite-branch
@@ -83,6 +83,10 @@ main() {
# Main #################################################################
+ wbranch="$obranch.tmp"
+
+ local revlist
+ local rebase
if git checkout "$obranch" -- 2>/dev/null; then
# obranch exists, update it
echo 'Updating existing rewritten branch...'
@@ -94,10 +98,6 @@ main() {
return 0
fi
- # Just to be safe
- git branch -D "$obranch.tmp" 2>/dev/null || true
-
- wbranch="$obranch.tmp"
local common="$(c2c "$obranch" "$ibranch" "$obranch")"
if c2c "$ibranch" "$ibranch" "${common}^" &>/dev/null; then
revlist="$(c2c "$obranch" "$ibranch" "$obranch")^..${wbranch}"
@@ -105,18 +105,20 @@ main() {
# There is only one commit from $ibranch in $obranch
revlist="$wbranch"
fi
+ rebase=true
else
# obranch does not exist, create it
echo 'Creating new rewritten branch...'
- wbranch=$obranch
revlist=$wbranch
+ rebase=false
fi
git checkout "$ibranch"
+ git branch -D "$wbranch" 2>/dev/null || true
git checkout -b "$wbranch"
git filter-branch -f "${filters[@]}" "$revlist"
- if [[ "$obranch" != "$wbranch" ]]; then
+ if $rebase; then
# rebase the changes in wbranch onto obranch
echo 'Rebasing rewrites onto existing branch...'
local wcommit="$(c2c "$wbranch" "$ibranch" "$wbranch")"
@@ -143,6 +145,8 @@ main() {
"${cmd[@]}"
git checkout "$obranch"
git branch -d "$wbranch"
+ else
+ git branch -m "$wbranch" "$obranch"
fi
}