Thread (35 messages) 35 messages, 7 authors, 2022-09-11

Re: [PATCH 1/2] ls-files: introduce "--format" option

From: ZheNing Hu <hidden>
Date: 2022-06-18 10:50:51

Ævar Arnfjörð Bjarmason [off-list ref] 于2022年6月16日周四 04:15写道:
quoted
+static void write_name_to_buf(struct strbuf *sb, const char *name)
+{
+     name = relative_path(name, prefix_len ? prefix : NULL, sb);
FWIW I'd find this a bit less "huh?" if we declared another variable
here, so just:

        const char *rel = relative_path(name, ...).
Yeah, It's just a wrong code copy.
quoted
+     o1
+     EOF
+     git ls-files --format="%(path)" -m >actual &&
+     test_cmp expect actual
+'
+
+test_expect_success 'git ls-files --format with -d' '
+     rm o1 &&
Don't "rm o1" here, rather have the test that creates it do:

    test_when_finished "rm o1" &&
    [the command that creates o1]
I thought about how to test 'git ls-files -d', so maybe I need
something like:

test_expect_success 'git ls-files --format with -d' '
     echo o3 >o3 &&
     git add o3 &&
     rm o3 &&
     cat >expect <<-\EOF &&
     o3
     EOF
     git ls-files --format="%(path)" -d >actual &&
     test_cmp expect actual
'
quoted
+     test_when_finished "git restore o1" &&
+     cat >expect <<-EOF &&
+     o1
+     EOF
+     git ls-files --format="%(path)" -d >actual &&
+     test_cmp expect actual
+'
+
These tests...:
quoted
+test_expect_success 'git ls-files --format with -s must fail' '
+     test_must_fail git ls-files --format="%(objectname)" -s
+'
+
+test_expect_success 'git ls-files --format with -o must fail' '
+     test_must_fail git ls-files --format="%(objectname)" -o
+'
+
+test_expect_success 'git ls-files --format with -k must fail' '
+     test_must_fail git ls-files --format="%(objectname)" -k
+'
+
+test_expect_success 'git ls-files --format with --resolve-undo must fail' '
+     test_must_fail git ls-files --format="%(objectname)" --resolve-undo
+'
+
+test_expect_success 'git ls-files --format with --deduplicate must fail' '
+     test_must_fail git ls-files --format="%(objectname)" --deduplicate
+'
+
+test_expect_success 'git ls-files --format with --debug must fail' '
+     test_must_fail git ls-files --format="%(objectname)" --debug
+'
...would be better done with a for-loop, so:

        for flag in -s -o -k --resolve-undo [...]
        do
                test_expect_success "git ls-files --format is incompatible with $flag" '
                        test_must_fail git ls-files --format="%(objectname)" $flag
                '
        done
Yeah, using this loop will be clear.
Note the '' on the second argument, that's intentional, as we eval it
you don't need "".
quoted
+test_done
Thanks for all these code style suggestions!

ZheNing Hu
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help