]> git.lizzy.rs Git - plan9front.git/commitdiff
git/branch: resolve implicit branch switch before using it
authorOri Bernstein <ori@eigenstate.org>
Wed, 16 Jun 2021 15:25:02 +0000 (15:25 +0000)
committerOri Bernstein <ori@eigenstate.org>
Wed, 16 Jun 2021 15:25:02 +0000 (15:25 +0000)
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.

sys/src/cmd/git/branch

index d3aa77d2bff99601631f235d119ba0c218a1bbdb..bf2027cc73bacc976f340efa23b8c10667470f2c 100755 (executable)
@@ -37,6 +37,15 @@ if not if(test -e .git/$new)
 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 '^..'}
 
@@ -49,14 +58,6 @@ if(~ $delete 1){
        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 */*)
        mkdir -p .git/`{basename -d $new}