shithub: git9

Download patch

ref: 42c2c790478e3ac433c20a0d30a74d5ddd2c46f3
parent: d69ce1ddfee9542e2163df305c22a15d5f62638c
author: Ori Bernstein <[email protected]>
date: Thu Jan 28 20:14:35 EST 2021

git/pull: merge local changes with remote changes

Many people using 9front will change programs to
their needs, and not making this a pain in the ass
seems welcome.

--- a/branch
+++ b/branch
@@ -4,7 +4,7 @@
 
 gitup
 
-flagfmt='a:listall, b:baseref ref, d:delete, n:newbr, s:stay'
+flagfmt='a:listall, b:baseref ref, d:delete, n:newbr, s:stay, m:merge'
 args='[branch]'
 eval `''{aux/getflags $*} || exec aux/usage
 
@@ -39,8 +39,8 @@
 modified=`$nl{git/query -c HEAD $base | grep '^[^-]' | subst '^..'}
 deleted=`$nl{git/query -c HEAD $base | grep '^-' | subst '^..'}
 
-if(! ~ $#modified 0 || ! ~ $#deleted 0){
-	git/walk -fRMA $modified $deleted || \
+if(! ~ $#modified 0 || ! ~ $#deleted 0 && ~ $#merge 0){
+	git/walk -fRMA $modified $deleted || 
 		die 'uncommited changes would be clobbered'
 }
 if(~ $delete 1){
@@ -68,28 +68,55 @@
 if(! ~ $#stay 0)
 	exit
 
-if(! ~ $#modified 0){
-	basedir=`{git/query -p $base}
-	for(m in $modified){
-		d=`{basename -d $m}
-		mkdir -p $d
-		mkdir -p .git/index9/tracked/$d
-		# Modifications can turn a file into
-		# a directory, or vice versa, so we
-		# need to delete and copy the files
-		# over. If we're checking out a
-		a=`{test -f $m && echo file || echo dir}
-		b=`{test -f $basedir/tree/$m && echo file || echo dir}
-		if(! ~ $a $b){
-			rm -rf $m
-			rm -rf .git/index9/tracked/$m
-		}
-		if(test -f $basedir/tree/$m){
-			cp  $basedir/tree/$m $m
-			walk -eq $m > .git/index9/tracked/$m
-		}
+basedir=`{git/query -p $base}
+cleanpaths=()
+dirtypaths=()
+if(! ~ $#modified 0 || ! ~ $#deleted 0){
+	cleanpaths=`$nl{git/walk -cfT $modified $deleted}
+	dirtypaths=`$nl{git/walk -cfRMA $modified $deleted}
+}
+for(m in $cleanpaths){
+	d=`{basename -d $m}
+	mkdir -p $d
+	mkdir -p .git/index9/tracked/$d
+	# Modifications can turn a file into
+	# a directory, or vice versa, so we
+	# need to delete and copy the files
+	# over.
+	a=`{test -f $m && echo file || echo dir}
+	b=`{test -f $basedir/tree/$m && echo file || echo dir}
+	if(! ~ $a $b){
+		rm -rf $m
+		rm -rf .git/index9/tracked/$m
 	}
+	if(test -f $basedir/tree/$m){
+		cp  $basedir/tree/$m $m
+		walk -eq $m > .git/index9/tracked/$m
+	}
 }
+for(ours in $dirtypaths){
+	common=/mnt/git/HEAD/tree/$ours
+	theirs=/mnt/git/object/$base/tree/$ours
+	n=$pid
+	tmp=$ours.tmp
+	while(test -f $tmp){
+		tmp=$tmp.$n
+		n=`{echo $n + 1 | hoc}
+	}
+	if(! test -f $ours)
+		ours=/dev/null
+	if(! test -f $theirs)
+		theirs=/dev/null
+	if(! test -f $common)
+		common=/dev/null
+	echo M $ours
+	if(! ape/diff3 -m $ours $common $theirs > $tmp)
+		echo '	'merge needed: $ours
+	echo > .git/index9/tracked/$ours
+	mv $tmp $ours
+}
+for(m in $localmods)
+	echo > .git/index9/tracked/$m
 if(! ~ $#deleted 0){
 	rm -f $deleted
 	rm -f .git/index9/tracked/$deleted
--- a/pull
+++ b/pull
@@ -76,5 +76,5 @@
 	git/log -s -e $local'..'$remote >[1=2]
 echo
 echo $remote':' `{git/query $local} '=>' `{git/query $remote}  >[1=2]
-git/branch -n -b $remote $local
+git/branch -mnb $remote $local
 exit ''