git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] git-mv: improve error message for conflicted file

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Jul 18, 2020, 06:55 UTC
Message-ID
<CAPig+cQpUu2UO-+jWn1nTaDykWnxwuEitzVB7PnW2SS_b7V8Hg@mail.gmail.com>
In-Reply-To
<CAPx1GvduDZw5pmfZHACDGZsMR5YYDowLw6+az+oL6oWLvDyCFA@mail.gmail.com>
On Fri, Jul 17, 2020 at 9:35 PM Chris Torek <chris.torek@gmail.com> wrote:
Show 5 quoted lines
> On Fri, Jul 17, 2020 at 4:47 PM Eric Sunshine <sunshine@sunshineco.com> wrote:
> > ... use literal TABs and let the here-doc provide the newlines.
>
> I personally hate depending on literal tabs, as they're really
> hard to see. If q_to_tab() is OK I'll use that.
q_to_tab() is a good choice.
Show 11 quoted lines
> > I realize that this test script is already filled with this sort of
> > thing where actions are performed outside of tests, however, these
> > days we frown upon that, and there really isn't a good reason to avoid
> > taking care of this clean up via the modern idiom of using
> > test_when_finished(), which you would call immediately after creating
> > the file in the test. So:
>
> Indeed, that's where I copied it from.
>
> Should I clean up other instances of separated-out `rm -f`s
> in this file in a separate commit?

In general, as a reviewer, I don't mind seeing a patch or two cleaning up style and other violations, however, the magnitude of the fixes this script needs is quite significant and would end up requiring a fair number of patches. As such, I'm not particularly eager to see the improvement made by this patch -- which is nicely standalone -- weighed down by a lengthy series of patches which aren't really related to it.

If cleaning up the t7001 test script is something you might be interested in doing, then making it a separate patch series would be more palatable. A scan of the script reveals the following problems, though there may be others:

* old style:
    test_expect_success \
        'title' \
        'body line 1 &&
        body line 2'
  should become:
    test_expect_success 'title' '
        body line 1 &&
        body line 2
    '
* test bodies should be indented with TAB, not spaces
* some tests use a deprecated style in which there are unnecessary
  blank lines after the opening quote of the test body and before the
  closing quote; these blanks lines should be removed
* style for `cd` in subshell is:
    (
        cd foo &&
        ...
    ) &&
  not:
    (cd foo &&
        ...
    ) &&
* there should be no whitespace after redirect operators, so:
    foo > actual &&
  should become:
    foo >actual &&
* tests 'cd' around and expect other tests to know the current
  directory and 'cd' relative to that; instead, any test which uses
  'cd' should do so in a subshell to ensure the current directory is
  restored by the time the test ends:
    test_expect_success 'title' '
        something &&
        (
            cd somewhere &&
            something-else
        )
    '
  Alternately, it may be possible to take advantage of `-C` if
  `something-else` is a `git` command:
    test_expect_success 'title' '
        something &&
        git -C somewhere foo
    '
* use `>` rather than `touch` to create an empty file when the
  timestamp isn't relevant to the test
* cleanup code outside of tests should be moved into the test and
  scheduled for execution via test_when_finished()
* there are several standalone "clean up" tests which invoke `git
  reset --hard` which should be folded into the tests for which they
  are cleaning up
* multiple commands on one line:
    mkdir foo && >foo/bar && git add foo/bar &&
  should be split across multiple lines:
    mkdir foo &&
    >foo/bar &&
    git add foo/bar &&
* at least one test incorrectly uses single quotes within the body of
  the test which itself is contained within single quotes; when
  quoting is needed inside a test body, it should be using double
  quotes instead; however, in this case, the quotes aren't even
  needed, so:
    git commit -m 'initial' &&
  can just become:
    git commit -m initial &&
* take advantage of here-docs, so:
    { echo other/a.txt; echo other/b.txt; } >expect &&
  can be expressed more cleanly as:
    cat >expect <<-\EOF &&
    other/a.txt
    other/b.txt
    EOF
* use `test` rather than `[`
* optional: rename the setup test 'prepare reference tree' to 'setup'
* optional modernization: use test_path_exists() and cousins instead
  of `test -f`, etc.
* optional: avoid `git` command upstream of a pipe since the pipe will
  swallow its exit code, thus a crash won't necessarily be noticed
* optional: it's unusual for tests to blast the test's ".git"
  directory and recreate it with `git init`, however, a number of
  tests in this script do so; for tests which really require a new
  repository, the more common approach is to use test_create_repo() to
  create a new repository into which the test can `cd` (in a subshell)
  without disturbing the repository used by the other tests in the
  script

A few of the above fixes can probably be combined into a single patch, in particular, the style fixes in the first four bullet points. Each remaining bullet point, however, probably deserves its own patch (including the one about removing whitespace after a redirect operator).

Previous: Chris TorekNext: Junio C Hamano
Message 4 of 11 in “git-mv: improve error message for conflicted file”
  1. git-mv: improve error message for conflicted fileChris Torek via GitGitGadget, Jul 17, 2020
  2. Eric SunshineJul 17, 2020
  3. Chris TorekJul 18, 2020
  4. Eric SunshineJul 18, 2020
  5. Junio C HamanoJul 18, 2020
  6. Elijah NewrenJul 18, 2020
  7. Junio C HamanoJul 18, 2020
  8. Elijah NewrenJul 19, 2020
  9. Junio C HamanoJul 19, 2020
  10. git-mv: improve error message for conflicted fileChris Torek via GitGitGadget, Jul 20, 2020
  11. Junio C HamanoJul 20, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.