From 1da1ac52d201bdc6656b91a4b1792581120b2d09 Mon Sep 17 00:00:00 2001 From: Ori Bernstein Date: Wed, 16 Jun 2021 15:25:02 +0000 Subject: 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. --- sys/src/cmd/git/branch | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/sys/src/cmd/git/branch b/sys/src/cmd/git/branch index d3aa77d2b..bf2027cc7 100755 --- a/sys/src/cmd/git/branch +++ b/sys/src/cmd/git/branch @@ -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} -- cgit v1.2.3