From d3ab1a5fcf3db26ba36fb5be07365908f7906ddb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Thu, 17 Mar 2022 19:08:35 +0100 Subject: reflog tests: add missing "git reflog exists" tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There were a few "git reflog exists" tests scattered over the test suite, but let's consolidate the testing of the main functionality into a new test file. This makes it easier to run just these tests during development. To do that amend and extend an existing test added in afcb2e7a3b8 (git-reflog: add exists command, 2015-07-21). Let's use "test_must_fail" instead of "!" (in case it segfaults), and test for basic usage, an unknown option etc. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- t/t1411-reflog-show.sh | 5 ----- t/t1418-reflog-exists.sh | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 5 deletions(-) create mode 100755 t/t1418-reflog-exists.sh (limited to 't') diff --git a/t/t1411-reflog-show.sh b/t/t1411-reflog-show.sh index 0bb319b944..975c4ea83a 100755 --- a/t/t1411-reflog-show.sh +++ b/t/t1411-reflog-show.sh @@ -169,9 +169,4 @@ test_expect_success 'git log -g -p shows diffs vs. parents' ' test_cmp expect actual ' -test_expect_success 'reflog exists works' ' - git reflog exists refs/heads/main && - ! git reflog exists refs/heads/nonexistent -' - test_done diff --git a/t/t1418-reflog-exists.sh b/t/t1418-reflog-exists.sh new file mode 100755 index 0000000000..60c6411ce3 --- /dev/null +++ b/t/t1418-reflog-exists.sh @@ -0,0 +1,32 @@ +#!/bin/sh + +test_description='Test reflog display routines' +GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main +export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME + +. ./test-lib.sh + +test_expect_success 'setup' ' + test_commit A +' + +test_expect_success 'usage' ' + test_expect_code 129 git reflog exists && + test_expect_code 129 git reflog exists -h +' + +test_expect_success 'usage: unknown option' ' + test_expect_code 129 git reflog exists --unknown-option +' + +test_expect_success 'reflog exists works' ' + git reflog exists refs/heads/main && + test_must_fail git reflog exists refs/heads/nonexistent +' + +test_expect_success 'reflog exists works with a "--" delimiter' ' + git reflog exists -- refs/heads/main && + test_must_fail git reflog exists -- refs/heads/nonexistent +' + +test_done -- cgit v1.2.3 From a34393f5f8152ad8bdbf15bccffc2be12a9a19ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Thu, 17 Mar 2022 19:08:38 +0100 Subject: reflog exists: use parse_options() API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change the "reflog exists" command added in afcb2e7a3b8 (git-reflog: add exists command, 2015-07-21) to use parse_options() instead of its own custom command-line parser. This continues work started in 33d7bdd6459 (builtin/reflog.c: use parse-options api for expire, delete subcommands, 2022-01-06). As a result we'll understand the --end-of-options synonym for "--", so let's test for that. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- t/t1418-reflog-exists.sh | 5 +++++ 1 file changed, 5 insertions(+) (limited to 't') diff --git a/t/t1418-reflog-exists.sh b/t/t1418-reflog-exists.sh index 60c6411ce3..d51ecd5e92 100755 --- a/t/t1418-reflog-exists.sh +++ b/t/t1418-reflog-exists.sh @@ -29,4 +29,9 @@ test_expect_success 'reflog exists works with a "--" delimiter' ' test_must_fail git reflog exists -- refs/heads/nonexistent ' +test_expect_success 'reflog exists works with a "--end-of-options" delimiter' ' + git reflog exists --end-of-options refs/heads/main && + test_must_fail git reflog exists --end-of-options refs/heads/nonexistent +' + test_done -- cgit v1.2.3 From e3c3675801f6d7494ac11e772e848981d1e158b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Thu, 17 Mar 2022 19:08:39 +0100 Subject: reflog: convert to parse_options() API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Continue the work started in 33d7bdd6459 (builtin/reflog.c: use parse-options api for expire, delete subcommands, 2022-01-06) and convert the cmd_reflog() function itself to use the parse_options() API. Let's also add a test which would fail if we forgot PARSE_OPT_NO_INTERNAL_HELP here, as well as making sure that we'll still pass through "--" by supplying PARSE_OPT_KEEP_DASHDASH. For that test we need to change "test_commit()" to accept files starting with "--". The "git reflog -h" usage will now show the usage for all of the sub-commands, rather than a terse summary which wasn't correct (e.g. "git reflog exists" is not a valid command). See my 8757b35d443 (commit-graph: define common usage with a macro, 2021-08-23) for prior art. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- t/t1410-reflog.sh | 17 +++++++++++++++++ t/test-lib-functions.sh | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) (limited to 't') diff --git a/t/t1410-reflog.sh b/t/t1410-reflog.sh index 68f69bb543..0dc36d842b 100755 --- a/t/t1410-reflog.sh +++ b/t/t1410-reflog.sh @@ -106,6 +106,23 @@ test_expect_success setup ' test_line_count = 4 output ' +test_expect_success 'correct usage on sub-command -h' ' + test_expect_code 129 git reflog expire -h >err && + grep "git reflog expire" err +' + +test_expect_success 'pass through -- to sub-command' ' + test_when_finished "rm -rf repo" && + git init repo && + test_commit -C repo message --a-file contents dash-tag && + + git -C repo reflog show -- --does-not-exist >out && + test_must_be_empty out && + git -C repo reflog show >expect && + git -C repo reflog show -- --a-file >actual && + test_cmp expect actual +' + test_expect_success rewind ' test_tick && git reset --hard HEAD~2 && test -f C && diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh index 0f439c99d6..1d00474458 100644 --- a/t/test-lib-functions.sh +++ b/t/test-lib-functions.sh @@ -329,7 +329,7 @@ test_commit () { else $echo "${3-$1}" >"$indir$file" fi && - git ${indir:+ -C "$indir"} add "$file" && + git ${indir:+ -C "$indir"} add -- "$file" && if test -z "$notick" then test_tick -- cgit v1.2.3 From fbc15b13f7380ee7b52fdcb467c3438c569fd5de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Thu, 17 Mar 2022 19:08:40 +0100 Subject: reflog [show]: display sensible -h output MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change the "git reflog show -h" output to show the usage summary relevant to it, rather than displaying the same output that "git log -h" would show. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Junio C Hamano --- t/t1410-reflog.sh | 5 +++++ 1 file changed, 5 insertions(+) (limited to 't') diff --git a/t/t1410-reflog.sh b/t/t1410-reflog.sh index 0dc36d842b..3f469353ec 100755 --- a/t/t1410-reflog.sh +++ b/t/t1410-reflog.sh @@ -111,6 +111,11 @@ test_expect_success 'correct usage on sub-command -h' ' grep "git reflog expire" err ' +test_expect_success 'correct usage on "git reflog show -h"' ' + test_expect_code 129 git reflog show -h >err && + grep -F "git reflog [show]" err +' + test_expect_success 'pass through -- to sub-command' ' test_when_finished "rm -rf repo" && git init repo && -- cgit v1.2.3