git/branch: make '-n' use HEAD when '-b' unspecified

This brings the behavior in line with the manual page,
and makes things less surprising for users.
This commit is contained in:
Ori Bernstein 2021-08-13 05:16:50 +00:00
parent 2af46e406b
commit da085a2d4c

View file

@ -32,7 +32,7 @@ if not
orig=`{git/query HEAD} orig=`{git/query HEAD}
if (~ $#baseref 1) if (~ $#baseref 1)
base=`{git/query $baseref} || exit 'bad base' base=`{git/query $baseref} || exit 'bad base'
if not if(test -e .git/$new) if not if(~ $#newbr 0)
base=`{git/query $new} base=`{git/query $new}
if not if not
base=`{git/query HEAD} base=`{git/query HEAD}
@ -41,7 +41,6 @@ if(~ $#newbr 0){
if(! ~ $#baseref 0) if(! ~ $#baseref 0)
die update would clobber $branch with $baseref die update would clobber $branch with $baseref
baseref=`$nl{echo -n $new | sed s@refs/heads/@refs/remotes/origin/@} baseref=`$nl{echo -n $new | sed s@refs/heads/@refs/remotes/origin/@}
echo $baseref
if(! test -e .git/$new) if(! test -e .git/$new)
if(! base=`{git/query $baseref}) if(! base=`{git/query $baseref})
die could not find branch $branch die could not find branch $branch
@ -119,4 +118,5 @@ if(! ~ $#deleted 0){
} }
echo ref: $new > .git/HEAD echo ref: $new > .git/HEAD
echo $new: `{git/query $new}
exit '' exit ''