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.
This commit is contained in:
Ori Bernstein 2021-06-16 15:25:02 +00:00
parent 7f697e822b
commit 1da1ac52d2

View file

@ -37,6 +37,15 @@ if not if(test -e .git/$new)
if not if not
base=`{git/query HEAD} 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 '^..'} modified=`$nl{git/query -c HEAD $base | grep '^[^-]' | subst '^..'}
deleted=`$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 echo 'deleted branch' $new
exit 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 commit=`{git/query $base} || die 'branch does not exist:' $base
if(~ $new */*) if(~ $new */*)
mkdir -p .git/`{basename -d $new} mkdir -p .git/`{basename -d $new}