git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2 2/9] Implement "git mv" for submodules

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 11, 2010, 01:25 UTC
Message-ID
<7v4ojisru8.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1270923830-11830-3-git-send-email-peter@pcc.me.uk>
Peter Collingbourne <peter@pcc.me.uk> writes:
> +		OPT_BOOLEAN('M', NULL, &skip_module_update, "don't upda...

If you are moving them by default, it is confusing to make up a negative "skip" option like this.

Instead, add a boolean "module_update" that defaults to true, and give "--[no-]module-update" without a short single-letter option, i.e.

	OPT_BOOLEAN(0 , "module-update", &module_update, "update submodule entries")
Exactly the same comment applies to your "git rm" patch.
Show 24 quoted lines
> @@ -96,13 +98,14 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
>  	/* Checking */
>  	for (i = 0; i < argc; i++) {
>  		const char *src = source[i], *dst = destination[i];
> -		int length, src_is_dir;
> +		int length, src_is_dir, pos;
>  		const char *bad = NULL;
>  
>  		if (show_only)
>  			printf("Checking rename of '%s' to '%s'\n", src, dst);
>  
>  		length = strlen(src);
> +		pos = cache_name_pos(src, length);
>  		if (lstat(src, &st) < 0)
>  			bad = "bad source";
>  		else if (!strncmp(src, dst, length) &&
> @@ -111,7 +114,9 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
>  		} else if ((src_is_dir = S_ISDIR(st.st_mode))
>  				&& lstat(dst, &st) == 0)
>  			bad = "cannot move directory over file";
> -		else if (src_is_dir) {
> +		else if (src_is_dir &&
> +				!(pos >= 0 &&
> +				  S_ISGITLINK(active_cache[pos]->ce_mode))) {
This looks like a funny indentation (perhaps a "diff" artifcat???)...
Show 22 quoted lines
> diff --git a/git-submodule.sh b/git-submodule.sh
> index de29f3a..f1e4e22 100755
> --- a/git-submodule.sh
> +++ b/git-submodule.sh
> @@ -859,6 +859,20 @@ cmd_sync()
>  		fi
>  	done
>  }
> +#
> +# Updates the entry in .gitmodules to move a submodule.
> +# This command is called by "git mv" for each submodule it moves.
> +#
> +cmd_mvconfig()
> +{
> +	src="$1"
> +	dst="$2"
> +
> +	name=$(module_name "$src") || exit
> +	git config -f .gitmodules submodule."$name".path "$dst" ||
> +		die "Could not update .gitmodules entry for $name"
> +	git add .gitmodules || die "Could not add .gitmodules to index"
> +}

This does not seem to depend on the first "give random name to submodules" patch in the series, or does it?

Previous: Peter CollingbourneNext: Peter Collingbourne
Message 5 of 14 in “Improve handling of moving and removing submodules”
  1. 0/9 Improve handling of moving and removing submodulesPeter Collingbourne, Apr 10, 2010
  2. 1/9 Generate unique ID for submodules created using "git submodule add"Peter Collingbourne, Apr 10, 2010
  3. Sverre RabbelierApr 10, 2010
  4. 2/9 Implement "git mv" for submodulesPeter Collingbourne, Apr 10, 2010
  5. Junio C HamanoApr 11, 2010
  6. 3/9 git rm: test failure behaviour for multiple removalsPeter Collingbourne, Apr 10, 2010
  7. 4/9 git rm: display a warning for every unremovable filePeter Collingbourne, Apr 10, 2010
  8. 5/9 git rm: collect file modesPeter Collingbourne, Apr 10, 2010
  9. 6/9 Add a mode parameter to the remove_path functionPeter Collingbourne, Apr 10, 2010
  10. Junio C HamanoApr 11, 2010
  11. 7/9 git rm: do not abort due to an initialised submodulePeter Collingbourne, Apr 10, 2010
  12. Junio C HamanoApr 11, 2010
  13. 8/9 git submodule: infrastructure for reading .gitmodules files in arbitrary locationsPeter Collingbourne, Apr 10, 2010
  14. 9/9 git rm: remove submodule entries from .gitmodulesPeter Collingbourne, Apr 10, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.