Commit Diff


commit - 2d61e38170df9e7e558024fa6f3c05196148f15a
commit + 360f3aea9198de6c93e8a185f87641b59c96dbfe
blob - f9bcb1bca8436bc052e3bdeab3be53a13add0a61
blob + 892b622a43e9f228674e275339385e0cebd26615
--- got/got.c
+++ got/got.c
@@ -5157,7 +5157,7 @@ cmd_diff(int argc, char *argv[])
 		error = got_error(GOT_ERR_OBJ_TYPE);
 		goto done;
 	}
-	if (type1 == GOT_OBJ_TYPE_BLOB && argc > 0) {
+	if (type1 == GOT_OBJ_TYPE_BLOB && argc > 2) {
 		error = got_error_msg(GOT_ERR_OBJ_TYPE,
 		    "path arguments cannot be used when diffing blobs");
 		goto done;
blob - 136f659b08eaf6408f6c79e05f6440fe7c754523
blob + 625dbd4435982c097244ab139e2218b1a1da0f0a
--- regress/cmdline/diff.sh
+++ regress/cmdline/diff.sh
@@ -19,6 +19,7 @@
 test_diff_basic() {
 	local testroot=`test_init diff_basic`
 	local head_rev=`git_show_head $testroot/repo`
+	local alpha_blobid=`get_blob_id $testroot/repo "" alpha`
 
 	got checkout $testroot/repo $testroot/wt > /dev/null
 	ret=$?
@@ -383,8 +384,39 @@ test_diff_basic() {
 	ret=$?
 	if [ $ret -ne 0 ]; then
 		diff -u $testroot/stderr.expected $testroot/stderr
+		return 1
+	fi
+
+	# diff two blob ids
+	(cd $testroot/wt && got commit -m 'edit' alpha >/dev/null)
+	local alpha_new_blobid=`get_blob_id $testroot/repo "" alpha`
+	(cd $testroot/wt && got diff $alpha_blobid $alpha_new_blobid) > $testroot/diff
+	ret=$?
+	if [ $ret -ne 0 ]; then
+		echo "diff failed unexpectedly" >&2
+		test_done "$testroot" "$ret"
+		return 1
+	fi
+
+	cat <<EOF >$testroot/diff.expected
+blob - $alpha_blobid
+blob + $alpha_new_blobid
+--- $alpha_blobid
++++ $alpha_new_blobid
+@@ -1 +1 @@
+-alpha
++modified alpha
+EOF
+
+	cmp -s $testroot/diff.expected $testroot/diff
+	ret=$?
+	if [ $ret -ne 0 ]; then
+		echo
+		diff -u $testroot/diff.expected $testroot/diff
+		test_done "$testroot" "$ret"
 		return 1
 	fi
+
 	test_done "$testroot" "$ret"
 }