git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Philippe Blain <levraiphilippeblain@gmail.com>
To: Tim Yorke <TYorke@visionrt.com>,
	"git@vger.kernel.org" <git@vger.kernel.org>
Subject: Re: FW: Bug Report: changes to submodule's files can be silently lost forever
Date: Thu, 21 Jan 2021 09:22:50 -0500	[thread overview]
Message-ID: <af8020e6-fe8f-1a48-aba9-f3ad9d7084e4@gmail.com> (raw)
In-Reply-To: <PA4PR08MB60967539EC75C9AACC4C46A5A9A10@PA4PR08MB6096.eurprd08.prod.outlook.com>

Hi Tim!

Le 2021-01-21 à 08:48, Tim Yorke a écrit :

> What did you do before the bug happened? (Steps to reproduce your issue)
> 
> - I used the command "git config submodule.recurse true" in my top-level repository
> - made a change to a file in a submodule (located within my top-level repository)
> - performed a git checkout in the top-level repository to a commit that didn't have the submodule
> - performed a git checkout in the top-level repository back to a commit that does have the submodule
> 
> What did you expect to happen? (Expected behavior)
> 
> When attempting the first checkout (i.e. to a commit without the submodule), I'd expect an warning telling me that the submodule was not up-to-date (uncommited changes). 


That's indeed very sensible.

> 
> What happened instead? (Actual behavior)
> 
> The changes to the file in the submodule were lost forever without any warning
> 
> What's different between what you expected and what actually happened?
> 
> My uncommitted changes were silently lost forever, whereas I'd expect either 
> - to be warned before I could continue or
> - the uncommited changes to be retained.
>

Thanks for the report. This is a known problem ([1], [2], [3]),
and I'm working on fixing it.

Just to be sure, the changes you lost were to a tracked file in
the submodule, right ? It was not a new, untracked file ?

I'm not quite ready yet to submit my fixes, but if you want to compile
Git from source in the meantime, the heart of the fix is this diff:


diff --git a/unpack-trees.c b/unpack-trees.c index 323280dd48..a3e3d98de1 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -1872,7 +1872,7 @@ static int verify_uptodate_1(const struct cache_entry *ce,
   
   		if (submodule_from_ce(ce)) {
   			int r = check_submodule_move_head(ce,
-				"HEAD", oid_to_hex(&ce->oid), o);
+				"HEAD", empty_tree_oid_hex(), o);
   			if (r)
   				return add_rejected_path(o, error_type, ce->name);
   			return 0;

This should prevent Git from switching branches if any tracked files are modified
in the submodule.

Cheers,

Philippe.

[1] https://lore.kernel.org/git/570e77a07f0b4d4ea09307e5fa819d6f@fiveco.ch/t/#u
[2] https://lore.kernel.org/git/20200525094019.22padbzuk7ukr5uv@overdrive.tratt.net/
[3] https://lore.kernel.org/git/CAHsG2VT4YB_nf8PrEmrHwK-iY-AQo0VDcvXGVsf8cEYXws4nig@mail.gmail.com/


      reply	other threads:[~2021-01-21 14:27 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <PA4PR08MB60969AFFD0607BDBE3ACBBE6A9A10@PA4PR08MB6096.eurprd08.prod.outlook.com>
2021-01-21 13:48 ` FW: Bug Report: changes to submodule's files can be silently lost forever Tim Yorke
2021-01-21 14:22   ` Philippe Blain [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=af8020e6-fe8f-1a48-aba9-f3ad9d7084e4@gmail.com \
    --to=levraiphilippeblain@gmail.com \
    --cc=TYorke@visionrt.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).