summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <LukeShu@sbcglobal.net>2013-01-29 14:22:40 -0500
committerLuke Shumaker <LukeShu@sbcglobal.net>2013-01-29 14:22:40 -0500
commita07981dc091b31127298c04a610f970cd5f1ad8d (patch)
tree42dd8946e3b17701cdc1744f40716d26c2a3fbe2
parenta6f4165f1dcd27e059195faf4c3c748e98e1f1d9 (diff)
Have git-rewrite-branch not create obranch until the end.
-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
}