Commit e730157933b56de990631fcd0c36592713b32120

Stefan Sperling 2019-03-18T16:54:15

fix 'got log PATH' in a bare git repository; broken by previous

diff --git a/got/got.c b/got/got.c
index 32ed259..c32eb50 100644
--- a/got/got.c
+++ b/got/got.c
@@ -835,16 +835,27 @@ cmd_log(int argc, char *argv[])
 		goto done;
 	error = NULL;
 
-	if (argc == 0)
+	if (argc == 0) {
 		path = strdup("");
-	else if (argc == 1) {
-		error = got_worktree_resolve_path(&path, worktree, argv[0]);
-		if (error)
+		if (path == NULL) {
+			error = got_error_from_errno();
 			goto done;
+		}
+	} else if (argc == 1) {
+		if (worktree) {
+			error = got_worktree_resolve_path(&path, worktree,
+			    argv[0]);
+			if (error)
+				goto done;
+		} else {
+			path = strdup(argv[0]);
+			if (path == NULL) {
+				error = got_error_from_errno();
+				goto done;
+			}
+		}
 	} else
 		usage_log();
-	if (path == NULL)
-		goto done;
 
 	repo_path = worktree ?
 	    strdup(got_worktree_get_repo_path(worktree)) : strdup(cwd);
diff --git a/regress/cmdline/log.sh b/regress/cmdline/log.sh
index 1e0c31a..2d890ea 100755
--- a/regress/cmdline/log.sh
+++ b/regress/cmdline/log.sh
@@ -16,6 +16,27 @@
 
 . ./common.sh
 
+function test_log_in_repo {
+	local testroot=`test_init log_in_repo`
+	local head_rev=`git_show_head $testroot/repo`
+
+	echo "commit $head_rev (master)" > $testroot/stdout.expected
+
+	for p in "" "." alpha epsilon epsilon/zeta; do
+		(cd $testroot/repo && got log $p | \
+			grep ^commit > $testroot/stdout)
+		cmp $testroot/stdout.expected $testroot/stdout
+		ret="$?"
+		if [ "$ret" != "0" ]; then
+			diff -u $testroot/stdout.expected $testroot/stdout
+			test_done "$testroot" "$ret"
+			return 1
+		fi
+	done
+
+	test_done "$testroot" "0"
+}
+
 function test_log_in_worktree {
 	local testroot=`test_init log_in_worktree`
 	local head_rev=`git_show_head $testroot/repo`
@@ -56,4 +77,5 @@ function test_log_in_worktree {
 	test_done "$testroot" "0"
 }
 
+run_test test_log_in_repo
 run_test test_log_in_worktree