shithub: riscv

Download patch

ref: 1da1ac52d201bdc6656b91a4b1792581120b2d09
parent: 7f697e822b2efd5c757141720469d105a5605ca4
author: Ori Bernstein <[email protected]>
date: Wed Jun 16 11:25:02 EDT 2021

git/branch: resolve implicit branch switch before using it

When switching a branch implicitly -- ie, creating a local
branch off of a remote branch -- we would get the list of
changed files before we would resolve the implicit branch
switch, leading to an empty list of changes.

--- a/sys/src/cmd/git/branch
+++ b/sys/src/cmd/git/branch
@@ -37,6 +37,15 @@
 if not
 	base=`{git/query HEAD}
 
+if(~ $#newbr 0){
+	if(! ~ $#baseref 0)
+		die update would clobber $branch with $baseref
+	baseref=`$nl{echo -n $new | sed s@refs/heads/@refs/remotes/origin/@}
+	echo $baseref
+	if(! test -e .git/$new)
+		if(! base=`{git/query $baseref})
+			die could not find branch $branch
+}
 modified=`$nl{git/query -c HEAD $base | grep '^[^-]' | subst '^..'}
 deleted=`$nl{git/query -c HEAD $base | grep '^-' | subst '^..'}
 
@@ -48,14 +57,6 @@
 	rm -f .git/$new
 	echo 'deleted branch' $new
 	exit
-}
-if(~ $#newbr 0){
-	if(! ~ $#baseref 0)
-		die update would clobber $branch with $baseref
-	baseref=`$nl{echo -n $new | sed s@refs/heads/@refs/remotes/origin/@}
-	if(! test -e .git/$new)
-		if(! base=`{git/query $baseref})
-			die could not find branch $branch
 }
 commit=`{git/query $base} || die 'branch does not exist:' $base
 if(~ $new */*)