On Mon, Apr 18, 2016 at 4:41 PM, Stefan Beller <sbeller@xxxxxxxxxx> wrote: > When directories are moved using `git mv` all files in the directory > have been just moved, but no further action was taken on them. This > was done by assigning the mode = WORKING_DIRECTORY to the files > inside a moved directory. > > submodules however need to update their link to the git directory as > well as updates to the .gitmodules file. By removing the condition of > `mode != INDEX` (the remaining modes are BOTH and WORKING_DIRECTORY) for > the required submodule actions, we perform these for submodules in a > moved directory. > > Signed-off-by: Stefan Beller <sbeller@xxxxxxxxxx> The patch looks good to me. I've marked some comments that I thought through while reviewing but it looks correct. > --- > builtin/mv.c | 39 ++++++++++++++++++++++----------------- > t/t7001-mv.sh | 16 ++++++++++++++++ > 2 files changed, 38 insertions(+), 17 deletions(-) > > diff --git a/builtin/mv.c b/builtin/mv.c > index 74516f4..2deb95b 100644 > --- a/builtin/mv.c > +++ b/builtin/mv.c > @@ -253,23 +253,28 @@ int cmd_mv(int argc, const char **argv, const char *prefix) > int pos; > if (show_only || verbose) > printf(_("Renaming %s to %s\n"), src, dst); > - if (!show_only && mode != INDEX) { > - if (rename(src, dst) < 0 && !ignore_errors) > - die_errno(_("renaming '%s' failed"), src); > - if (submodule_gitfile[i]) { > - if ((submodule_gitfile[i] != SUBMODULE_WITH_GITDIR && > - connect_work_tree_and_git_dir(dst, submodule_gitfile[i], &err)) || > - update_path_in_gitmodules(src, dst, &err)) { > - if (err.len) { > - if (ignore_errors) { > - warning("%s", err.buf); > - continue; > - } else > - die("%s", err.buf); > - } > - } else > - gitmodules_modified = 1; > - } > + if (show_only) > + continue; So here, we skip the item after displaying when we're in show only mode. That seems correct. > + if (mode != INDEX && > + rename(src, dst) < 0) { > + if (ignore_errors) > + continue; > + die_errno(_("renaming '%s' failed"), src); > + } Then when the mode isn't INDEX, we attempt the rename. > + > + if (submodule_gitfile[i]) { > + if ((submodule_gitfile[i] != SUBMODULE_WITH_GITDIR && > + connect_work_tree_and_git_dir(dst, submodule_gitfile[i], &err)) || > + update_path_in_gitmodules(src, dst, &err)) { > + if (err.len) { > + if (ignore_errors) { > + warning("%s", err.buf); > + continue; > + } else > + die("%s", err.buf); > + } > + } else > + gitmodules_modified = 1; > } Finally for all modes, we perform the steps for submodules. That makes sense to me. > This version results in a much larger diff, but I think the resulting code is much easier to follow. The use of the continue allows us to drop a layer of indentation making the remaining code a bit easier on the eyes. The patch description doesn't at first glance match the code change, since now it's a much larger chunk of moved code. However on inspection, I don't think anything needs to change, as it's just the conversion to if (show_only) { continue; } Reviewed-by: Jacob Keller <jacob.e.keller@xxxxxxxxx> Thanks, Jake -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html