shithub: git9

Download patch

ref: 80bca9e8fa64289e52841f66fbce62c0b4724b78
parent: 3313eba74efb302df2d39440c2e2be7372e65030
author: kvik <[email protected]>
date: Sun Jun 14 19:00:17 EDT 2020

Look for .git/HEAD to avoid getting fooled by mntgen(4)

To find the git repository root we used to search upwards, starting in
the current working directory, until a directory containing the  .git/ 
subdirectory was found or the  /  was reached.

This works fine but for the paths that cross over a mntgen(4) mountpoint,
such as /mnt, in which case the search always succeeds upon reaching the
mntgen(4), fooling git9 into thinking it found the repository root.

We work around this by looking for a file  .git/HEAD  instead, which
increases the likelihood that we have indeed found a git repository root.


--- a/conf.c
+++ b/conf.c
@@ -43,7 +43,7 @@
 	if((getwd(path, sizeof(path))) == nil)
 		sysfatal("could not get wd: %r");
 	while((p = strrchr(path, '/')) != nil){
-		snprint(buf, sizeof(buf), "%s/.git", path);
+		snprint(buf, sizeof(buf), "%s/.git/HEAD", path);
 		if(access(buf, AEXIST) == 0){
 			print("%s\n", path);
 			return;