summaryrefslogtreecommitdiff
path: root/git-rewrite-branch
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
commit0531586cb23eec0a23931f302eb8ecf0b52ff1d2 (patch)
tree1d37102e70ac1aa9271d7da0f0c24435a7288f29 /git-rewrite-branch
parente12c3b994c12284d971e962985edc5d872671ca9 (diff)
Have git-rewrite-branch not create obranch until the end.
Diffstat (limited to 'git-rewrite-branch')
-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
}