commit 4ad4d490cb44a8933d2cd76e15289ed47be82920 from: Mark Jamsek via: Thomas Adam date: Tue Aug 30 15:03:45 2022 UTC got: fix typo in argc check when diffing two blobs We already have two arguments when diffing two blobs, so check for more than two like we do when diffing two objects to check for invalid path args. Includes new regress test by op for diffing two blobs. ok stsp@ and ok plus regress test from op@ commit - 3387ec827ea9fb9e5704e084c10103af1623ec7d commit + 4ad4d490cb44a8933d2cd76e15289ed47be82920 blob - c608eb8d96bbda11a3a8eb5c9846e403ca0b71f9 blob + 211813953bcd89f62340834b3a8397639208843d --- 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 - e95a96d48ee8f125b8283577041ff01d0310081e blob + 11d5d92bcf596176592bfa4846aaf20ff1d1ef6d --- 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 <$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" }