support Git-style "lightweight" tags as arguments for 'got diff'
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 82 83 84 85 86 87 88 89 90 91 92
diff --git a/got/got.c b/got/got.c
index 4b74c05..2cffd89 100644
--- a/got/got.c
+++ b/got/got.c
@@ -2253,7 +2253,8 @@ match_object_id(struct got_object_id **id, char **label,
}
got_object_tag_close(tag);
return err;
- } else if (err->code != GOT_ERR_NO_OBJ)
+ } else if (err->code != GOT_ERR_OBJ_TYPE &&
+ err->code != GOT_ERR_NO_OBJ)
return err;
}
diff --git a/regress/cmdline/diff.sh b/regress/cmdline/diff.sh
index 43a0f3a..5df3441 100755
--- a/regress/cmdline/diff.sh
+++ b/regress/cmdline/diff.sh
@@ -238,6 +238,67 @@ function test_diff_tag {
test_done "$testroot" "$ret"
}
+function test_diff_lightweight_tag {
+ local testroot=`test_init diff_tag`
+ local commit_id0=`git_show_head $testroot/repo`
+ local tag1=1.0.0
+ local tag2=2.0.0
+
+ echo "modified alpha" > $testroot/repo/alpha
+ git_commit $testroot/repo -m "changed alpha"
+ local commit_id1=`git_show_head $testroot/repo`
+
+ (cd $testroot/repo && git tag $tag1)
+
+ echo "new file" > $testroot/repo/new
+ (cd $testroot/repo && git add new)
+ git_commit $testroot/repo -m "new file"
+ local commit_id2=`git_show_head $testroot/repo`
+
+ (cd $testroot/repo && git tag $tag2)
+
+ echo "diff $commit_id0 refs/tags/$tag1" > $testroot/stdout.expected
+ echo -n 'blob - ' >> $testroot/stdout.expected
+ got tree -r $testroot/repo -c $commit_id0 -i | grep 'alpha$' | \
+ cut -d' ' -f 1 >> $testroot/stdout.expected
+ echo -n 'blob + ' >> $testroot/stdout.expected
+ got tree -r $testroot/repo -i | grep 'alpha$' | cut -d' ' -f 1 \
+ >> $testroot/stdout.expected
+ echo '--- alpha' >> $testroot/stdout.expected
+ echo '+++ alpha' >> $testroot/stdout.expected
+ echo '@@ -1 +1 @@' >> $testroot/stdout.expected
+ echo '-alpha' >> $testroot/stdout.expected
+ echo '+modified alpha' >> $testroot/stdout.expected
+
+ got diff -r $testroot/repo $commit_id0 $tag1 > $testroot/stdout
+ 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 "diff refs/tags/$tag1 refs/tags/$tag2" > $testroot/stdout.expected
+ echo "blob - /dev/null" >> $testroot/stdout.expected
+ echo -n 'blob + ' >> $testroot/stdout.expected
+ got tree -r $testroot/repo -i -c $commit_id2 | grep 'new$' | \
+ cut -d' ' -f 1 | tr -d '\n' >> $testroot/stdout.expected
+ echo " (mode 644)" >> $testroot/stdout.expected
+ echo '--- /dev/null' >> $testroot/stdout.expected
+ echo '+++ new' >> $testroot/stdout.expected
+ echo '@@ -0,0 +1 @@' >> $testroot/stdout.expected
+ echo '+new file' >> $testroot/stdout.expected
+
+ got diff -r $testroot/repo $tag1 $tag2 > $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_diff_ignore_whitespace {
local testroot=`test_init diff_ignore_whitespace`
local commit_id0=`git_show_head $testroot/repo`
@@ -270,4 +331,5 @@ function test_diff_ignore_whitespace {
run_test test_diff_basic
run_test test_diff_shows_conflict
run_test test_diff_tag
+run_test test_diff_lightweight_tag
run_test test_diff_ignore_whitespace