mv: Fix spurious warning when moving a file in presence of submodules
In commit 0656781fa
"git mv" learned to update the submodule path in the
.gitmodules file when moving a submodule in the work tree. But since that
commit update_path_in_gitmodules() gets called no matter if we moved a
submodule or a regular file, which is wrong and leads to a bogus warning
when moving a regular file in a repo containing a .gitmodules file:
warning: Could not find section in .gitmodules where path=<filename>
Fix that by only calling update_path_in_gitmodules() when moving a
submodule. To achieve that, we introduce the special SUBMODULE_WITH_GITDIR
define to distinguish the cases where we also have to connect work tree
and git directory from those where we only need to update the .gitmodules
setting.
A test for submodules using a .git directory together with a .gitmodules
file has been added to t7001. Even though newer git versions will always
use a gitfile when cloning submodules, repositories cloned with older git
versions will still use this layout.
Reported-by: Matthieu Moy <Matthieu.Moy@grenoble-inp.fr>
Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
This commit is contained in:

committed by
Jonathan Nieder

parent
c5f424fd01
commit
04c1ee576a
13
builtin/mv.c
13
builtin/mv.c
@ -55,6 +55,7 @@ static const char *add_slash(const char *path)
|
||||
}
|
||||
|
||||
static struct lock_file lock_file;
|
||||
#define SUBMODULE_WITH_GITDIR ((const char *)1)
|
||||
|
||||
int cmd_mv(int argc, const char **argv, const char *prefix)
|
||||
{
|
||||
@ -132,6 +133,8 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
|
||||
submodule_gitfile[i] = read_gitfile(submodule_dotgit.buf);
|
||||
if (submodule_gitfile[i])
|
||||
submodule_gitfile[i] = xstrdup(submodule_gitfile[i]);
|
||||
else
|
||||
submodule_gitfile[i] = SUBMODULE_WITH_GITDIR;
|
||||
strbuf_release(&submodule_dotgit);
|
||||
} else {
|
||||
const char *src_w_slash = add_slash(src);
|
||||
@ -230,10 +233,12 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
|
||||
if (!show_only && mode != INDEX) {
|
||||
if (rename(src, dst) < 0 && !ignore_errors)
|
||||
die_errno (_("renaming '%s' failed"), src);
|
||||
if (submodule_gitfile[i])
|
||||
connect_work_tree_and_git_dir(dst, submodule_gitfile[i]);
|
||||
if (!update_path_in_gitmodules(src, dst))
|
||||
gitmodules_modified = 1;
|
||||
if (submodule_gitfile[i]) {
|
||||
if (submodule_gitfile[i] != SUBMODULE_WITH_GITDIR)
|
||||
connect_work_tree_and_git_dir(dst, submodule_gitfile[i]);
|
||||
if (!update_path_in_gitmodules(src, dst))
|
||||
gitmodules_modified = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (mode == WORKING_DIRECTORY)
|
||||
|
Reference in New Issue
Block a user