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

Re: [PATCH][RESEND] git-submodule: provide easy way of adding new submodules

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 23, 2007, 19:58 UTC
Message-ID
<7v8xaa4f5g.fsf@assigned-by-dhcp.pobox.com>
In-Reply-To
<20070621095300.GA27071MdfPADPa@greensroom.kotnet.org>
Sven Verdoolaege <skimo@kotnet.org> writes:
Show 9 quoted lines
>  COMMANDS
>  --------
> +add::
> +	Add the given repository as a submodule at the given path
> +	to the changeset to be committed next.  In particular, the
> +	repository is cloned at the specified path, added to the
> +	changeset and registered in .gitmodules.   If no path is
> +	specified, the path is deduced from the repository specification.
> +

Somehow "git submodule add $URL $my_subdirectory" feels unnatural, although it certainly is simpler to write the command usage string. Wouldn't a commit on the maintenance branch of cgit.git want to say "Add the 'maint' branch of git.git as my submodule", for example?

The alternatives I can come up with do not feel right either, though.
	git submodule $my_subdirectory $URL [$branch]
	git submodule $URL [--branch $branch] $my_subdirectory
Hmmm...
Show 14 quoted lines
> diff --git a/git-submodule.sh b/git-submodule.sh
> index 89a3885..3df7121 100755
> --- a/git-submodule.sh
> +++ b/git-submodule.sh
> @@ -1,13 +1,14 @@
>  #!/bin/sh
>  #
> -# git-submodules.sh: init, update or list git submodules
> +# git-submodules.sh: add, init, update or list git submodules
>  #
>  # Copyright (c) 2007 Lars Hjemli
>  
> -USAGE='[--quiet] [--cached] [status|init|update] [--] [<path>...]'
> +USAGE='[--quiet] [--cached] [add <repo>|status|init|update] [--] [<path>...]'

Can a single repo added at more than one path with this syntax? I do not see that in the code, but this implies such.

Show 22 quoted lines
>  . git-sh-setup
>  require_work_tree
>  
> +add=
>  init=
>  update=
>  status=
> @@ -25,6 +26,17 @@ say()
>  	fi
>  }
>  
> +get_repo_base() {
> +	(
> +		cd "`/bin/pwd`" &&
> +		cd "$1" || cd "$1.git" &&
> +		{
> +			cd .git
> +			pwd
> +		}
> +	) 2>/dev/null
> +}
> +

I've seen this code before elsewhere. We do not need to refactor right now with this patch, but please mark this copy with something like:

	# NEEDSWORK: identical function exists in get_repo_base
        # in clone.sh
	get_repo_base () {
        	...
as a reminder.
Show 30 quoted lines
> @@ -66,6 +78,44 @@ module_clone()
>  }
>  
>  #
> +# Add a new submodule to the working tree, .gitmodules and the index
> +#
> +# $@ = repo [path]
> +#
> +module_add()
> +{
> +	repo=$1
> +	path=$2
> +
> +	# Turn the source into an absolute path if
> +	# it is local
> +	if base=$(get_repo_base "$repo"); then
> +		repo="$base"
> +	fi
> +
> +	# Guess path from repo if not specified or strip trailing slashes
> +	if test -z "$path"; then
> +		path=$(echo "$repo" | sed -e 's|/*$||' -e 's|:*/*\.git$||' -e 's|.*[/:]||g')
> +	else
> +		path=$(echo "$path" | sed -e 's|/*$||')
> +	fi
> +
> +	test -e "$path" &&
> +	die "'$path' already exists"
> +
> +	module_clone "$path" "$repo" || exit
 - module_clone catches the "$path already exists" case; but the
   test is done differently.  One particular case of "an empty
   directory exists" is allowed there, but you are dying early
   to forbid it.  Is that warranted?  My gut feeling is that
   they should share the same check, iow, don't check yourself
   but have module_clone take care of the error case.
 - If $path does not exist in the worktree (because it hasn't
   been checked out), but does exist in the index, what should
   happen?  Should it be flagged as an error (in module_clone,
   not here)?
Previous: Junio C HamanoNext: Sven Verdoolaege
Message 4 of 10 in “[RESEND] git-submodule: provide easy way of adding new submodules”
  1. [RESEND] git-submodule: provide easy way of adding new submodulesSven Verdoolaege, Jun 21, 2007
  2. Lars HjemliJun 23, 2007
  3. Junio C HamanoJun 23, 2007
  4. Junio C HamanoJun 23, 2007
  5. Sven VerdoolaegeJun 24, 2007
  6. Junio C HamanoJun 24, 2007
  7. git-submodule: provide easy way of adding new submodulesSven Verdoolaege, Jun 24, 2007
  8. Junio C HamanoJun 25, 2007
  9. Sven VerdoolaegeJul 3, 2007
  10. Junio C HamanoJul 4, 2007

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.