git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [RFC] [BUDFIX] 'git rm --cached <submodule>' does not stage the changed .gitmodules
@ 2021-02-07 14:41 Shourya Shukla
  2021-02-07 19:30 ` Junio C Hamano
  0 siblings, 1 reply; 6+ messages in thread
From: Shourya Shukla @ 2021-02-07 14:41 UTC (permalink / raw)
  To: git; +Cc: gitster, christian.couder, levraiphilippeblain

Hello all,

I was lurking around 'gitgitgadget/git' when I saw this potential BUG
added by Phillipe Blaine (reported by Javier Mora):
https://github.com/gitgitgadget/git/issues/750

Link to the original mail by Javier:
https://lore.kernel.org/git/ea91c2ea29064079914f6a522db5115a@UUSALE0Z.utcmail.com/

In brief, 'git rm' does not stage the changed '.gitmodules' file when we
use the '--cached' option. Technically speaking, Git used to behave this
way only and hence this is not an unknown case. The test 45 of
't3600-rm.sh' already is prepared for this scenario and checks for
exactly the scenario as Javier describes.

So, my question is, do we need to fix this to make sure that the changed
'.gitmodules' is staged? I feel that we should because: since the SM
becomes irrelevant after executing 'git rm --cached', it's entry in
'.gitmodules' is a plain burden and is of no practical use.

The fault is in this section of 'builtin/rm.c':
https://github.com/git/git/blob/v2.30.0/builtin/rm.c#L378-L402

This part:

	const char *path = list.entry[i].name;
	if (list.entry[i].is_submodule) {
		strbuf_reset(&buf);
		strbuf_addstr(&buf, path);
		if (remove_dir_recursively(&buf, 0))
			die(_("could not remove '%s'"), path);

		removed = 1;
		if (!remove_path_from_gitmodules(path))
			gitmodules_modified = 1;
		continue;
	}

Needs to be executed irrespective of whether '--cached' is passed to the
command or not. In particular, the following if-statement is of utmost
importance:

	if (!remove_path_from_gitmodules(path))
		gitmodules_modified = 1;

Since the variable 'gitmodules_modified' is 0 when we pass 'cached', it
is not staged later here:

	if (gitmodules_modified)
		stage_updated_gitmodules(&the_index);

And its entry is not removed from the file. What should be done about
this? I would appreciate your opinions.

Regards,
Shourya Shukla


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-02-09  4:11 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-07 14:41 [RFC] [BUDFIX] 'git rm --cached <submodule>' does not stage the changed .gitmodules Shourya Shukla
2021-02-07 19:30 ` Junio C Hamano
2021-02-07 19:34   ` Junio C Hamano
2021-02-08  7:23   ` Shourya Shukla
2021-02-08 18:37     ` Junio C Hamano
2021-02-09  3:55   ` Philippe Blain

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).