shithub: git9

Download patch

ref: 74312782a4b50900203f826a0395134d41b2be6e
parent: e487c931e69d3c311a726490970edb0fa92704b6
author: Michael Forney <mforney@mforney.org>
date: Wed Feb 3 15:45:48 EST 2021

git/log: allow running from a subdirectory

This used to work in the rc implementation and there is some code to
calculate relative paths from the repository root, but it did not
change working directory so refs couldn't be resolved.

--- a/log.c
+++ b/log.c
@@ -295,9 +295,9 @@
 		break;
 	}ARGEND;
 
+	if(findrepo(repo, sizeof(repo)) == -1)
+		sysfatal("find root: %r");
 	if(argc != 0){
-		if(findrepo(repo, sizeof(repo)) == -1)
-			sysfatal("find root: %r");
 		if(getwd(path, sizeof(path)) == nil)
 			sysfatal("getwd: %r");
 		if(strlen(path) < strlen(repo))
@@ -311,6 +311,8 @@
 			free(r);
 		}
 	}
+	if(chdir(repo) == -1)
+		sysfatal("chdir: %r");
 
 	gitinit();
 	tmfmtinstall();