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

Re: [PATCHv4] submodule deinit: require '--all' instead of '.' for all submodules

From
Jonathan Nieder <jrnieder@gmail.com>
Date
May 4, 2016, 23:26 UTC
Message-ID
<20160504232642.GC395@google.com>
In-Reply-To
<1462401603-2067-1-git-send-email-sbeller@google.com>
Hi,
Stefan Beller wrote:
> Signed-off-by: Stefan Beller <sbeller@google.com>
> ---
> * reworded commit message slightly (realize, pathspec)
> * reworded the documentation 
Yay, thanks for your work on this.
[...]
Show 26 quoted lines
> +++ b/Documentation/git-submodule.txt
> @@ -13,7 +13,7 @@ SYNOPSIS
>  	      [--reference <repository>] [--depth <depth>] [--] <repository> [<path>]
>  'git submodule' [--quiet] status [--cached] [--recursive] [--] [<path>...]
>  'git submodule' [--quiet] init [--] [<path>...]
> -'git submodule' [--quiet] deinit [-f|--force] [--] <path>...
> +'git submodule' [--quiet] deinit [-f|--force] (-a|--all|[--] <path>...)
>  'git submodule' [--quiet] update [--init] [--remote] [-N|--no-fetch]
>  	      [-f|--force] [--rebase|--merge] [--reference <repository>]
>  	      [--depth <depth>] [--recursive] [--] [<path>...]
> @@ -140,12 +140,20 @@ deinit::
>  	tree. Further calls to `git submodule update`, `git submodule foreach`
>  	and `git submodule sync` will skip any unregistered submodules until
>  	they are initialized again, so use this command if you don't want to
> -	have a local checkout of the submodule in your work tree anymore. If
> +	have a local checkout of the submodule in your working tree anymore. If
>  	you really want to remove a submodule from the repository and commit
>  	that use linkgit:git-rm[1] instead.
> ++
> +When the command is run without pathspec, it errors out,
> +instead of deinit-ing everything, to prevent mistakes. In
> +version 2.8 and before the command gave a suggestion to use
> +'.' to unregister all submodules when it was invoked without
> +any argument, but this suggestion did not work and gave a
> +wrong message if you followed it in pathological cases and is
> +no longer recommended.

Why tell the user what happened in 2.8 and earlier? It's not clear what the reader would do with that information.

I think this paragraph could be removed. --all is explained lower down and the error message points it out to users who need it.

Show 5 quoted lines
>  +
> -If `--force` is specified, the submodule's work tree will be removed even if
> -it contains local modifications.
> +If `--force` is specified, the submodule's working tree will
> +be removed even if it contains local modifications.
(unnecessary rewrapping)
[...]
Show 10 quoted lines
>  update::
>  +
> @@ -247,6 +255,11 @@ OPTIONS
>  --quiet::
>  	Only print error messages.
>  
> +-a::
> +--all::
> +	This option is only valid for the deinit command. Unregister all
> +	submodules in the working tree.
This could use an explanation of why I'd want to use it.  E.g.
	This option is only valid for the deinit command. Unregister all
	submodules. Scripts should use this option instead of passing '.'
	to deinit because it works even in an empty repository with no
	submodules present.

Not about this patch: the organization of options is a little strange. A separate section with options for each subcommand would be easier to read.

Do we want to claim the short-and-sweet option -a? (I don't mind but it doesn't seem necessary.)

[...]
Show 8 quoted lines
> @@ -257,8 +270,8 @@ OPTIONS
>  --force::
>  	This option is only valid for add, deinit and update commands.
>  	When running add, allow adding an otherwise ignored submodule path.
> -	When running deinit the submodule work trees will be removed even if
> -	they contain local changes.
> +	When running deinit the submodule working trees will be removed even
> +	if they contain local changes.
Unrelated change?
[...]
Show 8 quoted lines
> @@ -544,9 +548,13 @@ cmd_deinit()
>  		shift
>  	done
>  
> -	if test $# = 0
> +	if test -n "$deinit_all" && test "$#" -ne 0
> +	then
> +		die "$(eval_gettext "--all and pathspec are incompatible")"

This message still feels too low-level to me, but I might be swimming uphill here.

Another option would be to call 'usage' and be done.
[...]
> --- a/t/t7400-submodule-basic.sh
> +++ b/t/t7400-submodule-basic.sh
Makes sense.

In the context of the original motivation: this patch improves the advice printed by plain "git submodule deinit" but doesn't help with existing callers that might have run "git submodule deinit .". It might make sense to handle '.' as a historical special case in a separate patch.

Thanks and sorry for all the complication, Jonathan

Previous: Junio C HamanoNext: Stefan Beller
Message 3 of 11 in “[PATCHv4] submodule deinit: require '--all' instead of '.' for all submodules”
  1. Stefan BellerMay 4, 2016
  2. Junio C HamanoMay 4, 2016
  3. Jonathan NiederMay 4, 2016
  4. Stefan BellerMay 4, 2016
  5. Jonathan NiederMay 4, 2016
  6. Junio C HamanoMay 5, 2016
  7. Jonathan NiederMay 5, 2016
  8. Stefan BellerMay 5, 2016
  9. Stefan BellerMay 5, 2016
  10. Junio C HamanoMay 5, 2016
  11. Stefan BellerMay 5, 2016

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.