shithub: front

Download patch

ref: f63dcb4b9b6b75347386c14429401d2d8d51db77
parent: 9482f887f984582725e0ffbfa2232d00780e87eb
author: Ori Bernstein <ori@eigenstate.org>
date: Fri Sep 13 12:28:32 EDT 2024

git/branch: handle dirents changing between file and dir correctly (thanks cinap)

--- a/sys/src/cmd/git/branch
+++ b/sys/src/cmd/git/branch
@@ -84,6 +84,14 @@
 }
 
 echo $commit > .git/$new
+
+for(d in $deleted){
+	if(! test -d $d){
+		rm -f $d
+		echo R NOQID 0 $d >> .git/INDEX9
+	}
+}
+
 for(m in $cleanpaths){
 	d=`$nl{basename -d $m}
 	mkdir -p $d
@@ -112,13 +120,6 @@
 	common=$gitfs/object/$orig/tree/$ours
 	theirs=$gitfs/object/$base/tree/$ours
 	merge1 $ours $ours $common $theirs
-}
-
-for(d in $deleted){
-	if(! test -d $d){
-		rm -f $d
-		echo R NOQID 0 $d >> .git/INDEX9
-	}
 }
 
 echo ref: $new > .git/HEAD
--- /dev/null
+++ b/sys/src/cmd/git/test/ftype.rc
@@ -1,0 +1,41 @@
+#!/bin/rc
+
+. util.rc
+
+rm -fr scratch
+mkdir -p scratch/repo1
+
+echo @@ file-type change @@
+@{
+	rfork ne
+	cd scratch/repo1
+	repo1=`{pwd}
+	$G/init
+	echo A > A
+	mkdir B
+	echo B > B/B
+	$G/add A
+	$G/commit -m 1 A
+
+	cd ..
+	$G/clone $repo1 repo2
+	cd repo2
+	repo2=`{pwd}
+
+	cd $repo1
+	rm A
+	rm -rf B
+	mkdir A
+	echo B > A/B
+	echo B > B
+	$G/add A/B
+	$G/add B
+	$G/commit -m 2 A/B B
+
+	# pull repo2 after file changed to directory in repo1
+	cd $repo2
+	$G/pull
+
+	# make sure A is the same in both repos
+	diff -r $repo1/A $repo2/A || echo fuck
+}
--- a/sys/src/cmd/git/test/mkfile
+++ b/sys/src/cmd/git/test/mkfile
@@ -4,6 +4,7 @@
 	add\
 	basic\
 	export\
+	ftype\
 	lca\
 	merge\
 	range
--- a/sys/src/cmd/git/util.c
+++ b/sys/src/cmd/git/util.c
@@ -67,8 +67,15 @@
 				cb = '/';
 			return (ca > cb) ? 1 : -1;
 		}
-		if(ca == 0)
-			return 0;
+		if(ca == 0){
+			if(ae->mode & DMDIR)
+				ca = '/';
+			if(be->mode & DMDIR)
+				cb = '/';
+			if(ca == cb)
+				return 0;
+			return (ca > cb) ? 1 : -1;
+		}
 	}
 }
 
--