fix 'got log PATH' in a bare git repository; broken by previous
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
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