improve commit graph's error handling of non-existent paths
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
diff --git a/lib/commit_graph.c b/lib/commit_graph.c
index ce6e873..a205e68 100644
--- a/lib/commit_graph.c
+++ b/lib/commit_graph.c
@@ -497,6 +497,16 @@ got_commit_graph_iter_start(struct got_commit_graph *graph,
return err;
}
+ if (graph->iter_node == NULL) {
+ const char *path;
+ if (got_path_is_root_dir(graph->path))
+ return got_error_no_obj(id);
+ path = graph->path;
+ while (path[0] == '/')
+ path++;
+ return got_error_path(path, GOT_ERR_NO_TREE_ENTRY);
+ }
+
return NULL;
}
diff --git a/regress/cmdline/log.sh b/regress/cmdline/log.sh
old mode 100755
new mode 100744
index 8e9f809..f4d3997
--- a/regress/cmdline/log.sh
+++ b/regress/cmdline/log.sh
@@ -265,9 +265,44 @@ function test_log_limit {
test_done "$testroot" "0"
}
+function test_log_nonexistent_path {
+ local testroot=`test_init log_nonexistent_path`
+ local head_rev=`git_show_head $testroot/repo`
+
+ echo "commit $head_rev (master)" > $testroot/stdout.expected
+
+ (cd $testroot/repo && got log this/does/not/exist \
+ > $testroot/stdout 2> $testroot/stderr)
+ ret="$?"
+ if [ "$ret" == "0" ]; then
+ echo "log command succeeded unexpectedly" >&2
+ test_done "$testroot" "1"
+ return 1
+ fi
+
+ echo -n > $testroot/stdout.expected
+ cmp -s $testroot/stdout.expected $testroot/stdout
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/stdout.expected $testroot/stdout
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ echo "got: this/does/not/exist: no such entry found in tree" \
+ > $testroot/stderr.expected
+ cmp -s $testroot/stderr.expected $testroot/stderr
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/stderr.expected $testroot/stderr
+ fi
+ test_done "$testroot" "$ret"
+}
+
run_test test_log_in_repo
run_test test_log_in_bare_repo
run_test test_log_in_worktree
run_test test_log_in_worktree_with_path_prefix
run_test test_log_tag
run_test test_log_limit
+run_test test_log_nonexistent_path