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

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

From
Elijah Newren <newren@gmail.com>
Date
Jul 18, 2020, 02:00 UTC
Message-ID
<CABPp-BGDp_SjJKvi+XVd6KvRLA5PVsK4xBLPvBxAimDft+0M9g@mail.gmail.com>
In-Reply-To
<xmqqeep9d6tm.fsf@gitster.c.googlers.com>
On Fri, Jul 17, 2020 at 5:12 PM Junio C Hamano <gitster@pobox.com> wrote:
Show 32 quoted lines
>
> "Chris Torek via GitGitGadget" <gitgitgadget@gmail.com> writes:
>
> > -             } else if (cache_name_pos(src, length) < 0)
> > -                     bad = _("not under version control");
> > -             else if (lstat(dst, &st) == 0 &&
> > +             } else if (cache_name_pos(src, length) < 0) {
> > +                     /*
> > +                      * This occurs for both untracked files *and*
> > +                      * files that are in merge-conflict state, so
> > +                      * let's distinguish between those two.
> > +                      */
> > +                     struct cache_entry *ce = cache_file_exists(src, length, ignore_case);
> > +                     if (ce == NULL)
> > +                             bad = _("not under version control");
> > +                     else
> > +                             bad = _("must resolve merge conflict first");
>
>
> The original did not care about the cache entry itself, and that is
> why cache_name_pos() was used.  Now you care what cache entry is at
> that position, running both calls is quite wasteful.
>
> Would it work better to declare "struct cache_entry *ce" in the
> scope that surrounds this if/elseif cascade and then rewrite this
> part more like so:
>
>         } else if (!(ce = cache_file_exists(...)) {
>                 bad = _("not tracked");
>         } else if (ce_stage(ce)) {
>                 bad = _("conflicted");
>         } else if (lstat(...)) { ...

Or, even better, make ce_stage(ce) not be an error; see https://lore.kernel.org/git/xmqqk1ozb6qy.fsf@gitster-ct.c.googlers.com/.

I hadn't gotten around to it yet, but it's still on my radar.

(That said, I've obviously taken a really long time to get to it, so improving the error message as an interim step is perfectly fine.)

Previous: Junio C HamanoNext: Junio C Hamano
Message 6 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.