ref: af842ca41a10f88089bd38bcd22a14b68e5aef63
parent: a3ee5e0888d1460a3365a5d94764344269cb2ad3
author: mia soweli <mia@soweli.net>
date: Wed May 28 12:29:45 EDT 2025
git/branch: branches at the same commit may not be the same in order to prevent removing the current branch git tests the head against the specified branch name, however it is over eager, considering any branches at the same commit hash identical. this results in rebase not working because when finished, the work branch is at the same commit as HEAD.
--- a/sys/src/cmd/git/branch
+++ b/sys/src/cmd/git/branch
@@ -31,6 +31,7 @@
new=refs/heads/$branch
orig=`{git/query HEAD}
+origbranch=refs/`{awk '$1=="branch"{print $2}' < $gitfs/ctl}
if (~ $#baseref 1)
base=`{git/query $baseref} || exit 'bad base'
if not if(~ $#newbr 0)
@@ -50,7 +51,7 @@
deleted=`$nl{git/query -c HEAD $base | grep '^-' | subst '^..'}
# if we remove the current branch without switching, bad things happen
-if(~ $remove 1 && ~ `{git/query HEAD} `{git/query $branch})
+if(~ $remove 1 && ~ $origbranch $new)
die 'cannot remove current branch'
# if we're not merging, don't clobber existing changes.
if(~ $#merge 0 && ~ $#remove 0){
--- a/sys/src/cmd/git/test/mkfile
+++ b/sys/src/cmd/git/test/mkfile
@@ -9,7 +9,8 @@
lca\
merge\
noam\
- range
+ range\
+ rebase
</sys/src/cmd/mktest
--- /dev/null
+++ b/sys/src/cmd/git/test/rebase.rc
@@ -1,0 +1,26 @@
+#!/bin/rc
+
+. ./util.rc
+
+rm -fr scratch
+mkdir scratch
+
+echo @@ rebase test @@
+@{
+ cd scratch
+ q git/init
+ q echo a >a; git/add a; git/commit -m a a
+
+ q git/branch -n front-test
+ echo c >c;
+ q git/add c
+ q git/commit -m c c
+
+ q git/branch front
+ echo b >b;
+ q git/add b
+ q git/commit -m b b
+
+ q git/branch front-test
+ q git/rebase front
+}
--
⑨