shithub: git9

Download patch

ref: ba26692dbfcbea5231d02edd318a5dfbf8f22db3
parent: 221e7c96b417e63b291f83714d9dbcbb253a2e4b
author: Ori Bernstein <[email protected]>
date: Wed Dec 9 12:54:52 EST 2020

git/branch: implcitly create local branch off origin

Currently, creating a local branch off a remote one requires
passing the '-nb origin/$branch' argument to git/branch.

In addition to being annoying, it opens up the possibility for
human error, since passing this argument for an existing branch
will clobber it.

After this change, a repo in this state:

	% git/branch -a
	heads/master
	remote/origin/master
	remote/origin/foo

will switch to heads/master when running:

	% git/branch master

but will create a new branch foo, based off origin/foo,
when running:

	% git/branch foo

--- a/branch
+++ b/branch
@@ -51,10 +51,12 @@
 	exit
 }
 if(~ $#newbr 0){
-	if(! test -e .git/$new)
-		die could not find branch $branch
 	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
 echo updating $new to $commit