fix "no such entry found in tree" error with got log -p and an added path ok millert@
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 77 78 79 80 81
diff --git a/got/got.c b/got/got.c
index 7bf9457..874e65a 100644
--- a/got/got.c
+++ b/got/got.c
@@ -2923,13 +2923,16 @@ print_patch(struct got_commit_object *commit, struct got_object_id *id,
err = got_object_id_by_path(&obj_id1, repo,
qid->id, path);
if (err) {
- free(obj_id2);
- goto done;
- }
- err = got_object_id_str(&id_str1, obj_id1);
- if (err) {
- free(obj_id2);
- goto done;
+ if (err->code != GOT_ERR_NO_TREE_ENTRY) {
+ free(obj_id2);
+ goto done;
+ }
+ } else {
+ err = got_object_id_str(&id_str1, obj_id1);
+ if (err) {
+ free(obj_id2);
+ goto done;
+ }
}
}
err = got_object_get_type(&obj_type, repo, obj_id2);
diff --git a/regress/cmdline/log.sh b/regress/cmdline/log.sh
index ea958f5..b05b0f4 100755
--- a/regress/cmdline/log.sh
+++ b/regress/cmdline/log.sh
@@ -283,6 +283,40 @@ function test_log_limit {
test_done "$testroot" "0"
}
+function test_log_patch_added_file {
+ local testroot=`test_init log_patch_added_file`
+ local commit_id0=`git_show_head $testroot/repo`
+
+ got checkout $testroot/repo $testroot/wt > /dev/null
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ echo "new file" > $testroot/wt/new
+ (cd $testroot/wt && got add new >/dev/null)
+ (cd $testroot/wt && got commit -m 'test log_limit' > /dev/null)
+ local commit_id1=`git_show_head $testroot/repo`
+
+ echo "commit $commit_id1 (master)" > $testroot/stdout.expected
+ # This used to fail with 'got: no such entry found in tree'
+ (cd $testroot/wt && got log -l1 -p new > $testroot/stdout.patch)
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ echo "got log command failed unexpectedly" >&2
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+ grep ^commit $testroot/stdout.patch > $testroot/stdout
+ cmp -s $testroot/stdout.expected $testroot/stdout
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/stdout.expected $testroot/stdout
+ fi
+ test_done "$testroot" "$ret"
+}
+
function test_log_nonexistent_path {
local testroot=`test_init log_nonexistent_path`
local head_rev=`git_show_head $testroot/repo`
@@ -618,6 +652,7 @@ 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_patch_added_file
run_test test_log_nonexistent_path
run_test test_log_end_at_commit
run_test test_log_reverse_display