shithub: git9

Download patch

ref: 8e273a31aa38892117df891dce8ce8e1c05790f9
parent: 972518e469bfacee38782551f1911e7ef10efb95
author: Ori Bernstein <ori@eigenstate.org>
date: Sun Jan 26 12:01:36 EST 2020

make accidental clobbers harder

--- a/branch
+++ b/branch
@@ -1,41 +1,51 @@
-#!/bin/rc -e
+#!/bin/rc
 rfork en
 . /sys/lib/git/common.rc
 
 usage='
-	git/branch [-cdsu] [-b base] [new]
+	git/branch [-cdsu] [-b base] [branch]
 		-b base   base new branch on "base" (default: current branch)
-		-d        delete a branch
-		-s        create a branch but stay on current one
+		-c        clobber or create branch
+		-d        delete branch
+		-s        create branch but stay on current one
 '
 
+
+fn resolvebranch {
+
+}
+
 gitup
 
 stay=()
 create=()
 delete=()
-base=()
+baseref=()
+modified=()
+deleted=()
+
 while(~ $1 -* && ! ~ $1 --){
 	switch($1){
 	case -c; create=true
 	case -s; stay=true
-	case -b; shift; base=$1
+	case -b; baseref=$2; shift
 	case -d; delete=true
-	case -u; update=true
 	case *
 		usage
 	}
 	shift
 }
-if(~ $1 --) shift
 
+if(~ $1 --)
+	shift
+
 if(~ $#* 0){
 	awk '$1=="branch"{print $2}' < /mnt/git/ctl
 	exit
 }
-
 if(! ~ $#* 1)
 	usage
+
 if(~ $1 refs/heads/*)
 	new=$1
 if not if(~ $1 heads/*)
@@ -42,33 +52,35 @@
 	new=refs/$1
 if not
 	new=refs/heads/$1
-if (~ $#base 1)
-	base=`{git/query $base}
+if (~ $#baseref 1)
+	base=`{git/query $baseref}
 if not if(test -e .git/$new)
 	base=`{git/query $new}
 if not
 	base=`{git/query HEAD}
 
+modified=`$nl{git/query -c HEAD $base | grep '^[^-]' | sed 's/^..//'}
+deleted=`$nl{git/query -c HEAD $base | grep '^-' | sed 's/^..//'}
+
+if(! ~ $#modified 0 || ! ~ $#deleted 0){
+	if(! git/walk -q $modified $deleted){
+		git/walk -fRMA $modified $deleted
+		die 'uncommited changes would be clobbered'
+	}
+}
 if(! ~ $#delete 0){
 	rm -f .git/$new
 	exit
 }
-
-
-modified=`$nl{git/query -c HEAD $base | grep '^[^-]' | sed 's/^..//'}
-deleted=`$nl{git/query -c HEAD $base | grep '^-' | sed 's/^..//'}
-
-if(! git/walk -q $modified $deleted)
-	die 'uncommited changes'
-if(! ~ $#create 0){
+if(~ $#create 0){
 	if(! test -e .git/$new)
-		die 'branch does not exist:' $new
+		die could not find branch $1
+	if(! ~ $#baseref 0)
+		die update would clobber $1 with $baseref
 }
-if not{
-	commit=`{git/query $base || die 'branch does not exist:' $base}
-	echo updating $new to $commit
-	echo $commit > .git/$new
-}
+commit=`{git/query $base || die 'branch does not exist:' $base}
+echo updating $new to $commit
+echo $commit > .git/$new
 
 
 if(! ~ $#stay 0)