archive mirror
 help / color / mirror / Atom feed
From: Shourya Shukla <>
Subject: [RFC] [BUDFIX] 'git rm --cached <submodule>' does not stage the changed .gitmodules
Date: Sun, 7 Feb 2021 20:11:44 +0530	[thread overview]
Message-ID: <20210207144144.GA42182@konoha> (raw)

Hello all,

I was lurking around 'gitgitgadget/git' when I saw this potential BUG
added by Phillipe Blaine (reported by Javier Mora):

Link to the original mail by Javier:

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
'' 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':

This part:

	const char *path = list.entry[i].name;
	if (list.entry[i].is_submodule) {
		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;

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

	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)

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

Shourya Shukla

             reply	other threads:[~2021-02-07 14:44 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-07 14:41 Shourya Shukla [this message]
2021-02-07 19:30 ` [RFC] [BUDFIX] 'git rm --cached <submodule>' does not stage the changed .gitmodules 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

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:

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

  git send-email \
    --in-reply-to=20210207144144.GA42182@konoha \ \ \ \ \ \

* 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).