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

Re: [PATCH] Do not record unstaged deleted file upon recursive merge if file was moved outside of working tree with enabled sparse-checkout.

From
Mikhail Filippov <mikhail@filippov.me>
Date
Sep 12, 2016, 08:38 UTC
Message-ID
<798801473669480@web11o.yandex.ru>
In-Reply-To
<xmqqeg4q6mw4.fsf@gitster.mtv.corp.google.com>
It's a very unexpected behaviour when a user sees a deleted file after a merge with enabled sparse-checkout. Moreover, when the user resolves merge conflicts and commits the changes with the command "git commit -am xxx", a repository can be broken because all the moved files will be deleted. Finally, it's really hard to find a user who deleted these files because "git log file" doesn't show any merge commits by default. I'm not sure that my fix is correct but I checked all tests and I didn't find a better way to prevent files deleting.
12.09.2016, 02:24, "Junio C Hamano" <gitster@pobox.com>:
Show 60 quoted lines
>    Mikhail Filippov <mikhail@filippov.me> writes:
>
>>     ---
>
>    You'd need a lot more explanation on why this is needed
>    (i.e. without it what behaviour you would get, and why that
>    behaviour is wrong).
>
>>      merge-recursive.c | 9 +++++---
>>      t/t6042-merge-rename-corner-cases.sh | 42 ++++++++++++++++++++++++++++++++++++
>>      2 files changed, 48 insertions(+), 3 deletions(-)
>>
>>     diff --git a/merge-recursive.c b/merge-recursive.c
>>     index e349126..25dc701 100644
>>     --- a/merge-recursive.c
>>     +++ b/merge-recursive.c
>>     @@ -1724,9 +1724,12 @@ static int merge_content(struct merge_options *o,
>>                       */
>>                      path_renamed_outside_HEAD = !path2 || !strcmp(path, path2);
>>                      if (!path_renamed_outside_HEAD) {
>>     - add_cacheinfo(o, mfi.mode, &mfi.oid, path,
>>     - 0, (!o->call_depth), 0);
>>     - return mfi.clean;
>>     + struct stat st;
>>     + if (lstat(path, &st) == 0) {
>>     + add_cacheinfo(o, mfi.mode, &mfi.oid, path,
>>     + 0, (!o->call_depth), 0);
>>     + return mfi.clean;
>>     + }
>
>    I cannot guess what you are trying to achieve without explanation in
>    the proposed log message, but I can say that this unconditional
>    checking of a working tree file cannot be correct (there may or may
>    not be other things that are wrong with this change, which cannot be
>    judged without more information).
>
>    Imagine your o->call_depth is not zero, i.e. we are making a virtual
>    common ancestor with this merge, in which case any of the three
>    trees involved may have nothing to do with the current working tree
>    files.
>
>>     +test_expect_success 'move file/sparse-checkout/merge should not delete moved file' '
>>     + git rm -rf . &&
>>     + git clean -fdqx &&
>>     + rm -rf .git &&
>>     + git init &&
>
>    Yuck. This is inherited from existing tests but I think they need
>    to be cleaned up. It is not your fault, and it is not in the scope
>    of this change.
>
>>     + git status >output &&
>>     + cp output /tmp/a &&
>
>    Huh?
>
>>     + test_i18ngrep "nothing to commit" output
>>     +'
>>     +
>>      test_done
-- 
Mikhail Filippov 
Software Developer
JetBrains
http://jetbrains.com
“The Drive To Develop"
Previous: Junio C HamanoNext: Mikhail Filippov
Message 3 of 4 in “Do not record unstaged deleted file upon recursive merge if file was moved outside of working tree with enabled sparse-checkout.”
  1. Do not record unstaged deleted file upon recursive merge if file was moved outside of working tree with enabled sparse-checkout.Mikhail Filippov, Sep 11, 2016
  2. Junio C HamanoSep 11, 2016
  3. Mikhail FilippovSep 12, 2016
  4. Mikhail FilippovSep 12, 2016

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.