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

Re: [PATCH v3] [submodule] Add --depth to submodule update/add

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 2, 2013, 19:01 UTC
Message-ID
<7v7gh8947e.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1372729167-23200-1-git-send-email-iveqy@iveqy.com>
Fredrik Gustafsson <iveqy@iveqy.com> writes:
Show 7 quoted lines
> git clone dies with the error "too many arguments". This was solved with changing
> depth=$5
> to
> depth="$5"
>
> which I don't understand since variable assignment doesn't expand $5 and therefore
> "" should not be needed, AFAIK. Any comments on this?
A red herring?
Show 5 quoted lines
> @@ -211,6 +212,7 @@ module_clone()
>  	name=$2
>  	url=$3
>  	reference="$4"
> +	depth="$5"

If the caller gave you only 4 arguments, depth will become an empty string with or without dq around $5 here. And

> -			git clone $quiet -n ${reference:+"$reference"} \
> +			git clone $quiet $depth -n ${reference:+"$reference"} \
>  				--separate-git-dir "$gitdir" "$url" "$sm_path"

... you use $depth without dq around it, so when $depth is empty string, "git clone" will not see it at all (not even an empty string as one of its arguments).

Which is probably fine, as long as the caller makes sure it will not call this function as

	module_clone 1 2 3 4 "depth argument as multi-word"
which will be split at $IFS.

If you know $depth must be passed as a single argument (or no argument when the caller did not give you any) to the underlying "git clone", you can write it like so:

		...
		depth=$5
		...
		git clone $quiet ${depth:+"$depth"} -n ...
Previous: Junio C Hamano
Message 11 of 11 in “[submodule] Add --depth to submodule update/add”
  1. [submodule] Add --depth to submodule update/addFredrik Gustafsson, Jul 2, 2013
  2. Andreas SchwabJul 2, 2013
  3. Jens LehmannJul 2, 2013
  4. [submodule] Add --depth to submodule update/addFredrik Gustafsson, Jul 2, 2013
  5. Jens LehmannJul 2, 2013
  6. [submodule] Add --depth to submodule update/addFredrik Gustafsson, Jul 2, 2013
  7. Jens LehmannJul 3, 2013
  8. Junio C HamanoJul 3, 2013
  9. Fredrik GustafssonJul 3, 2013
  10. Junio C HamanoJul 3, 2013
  11. Junio C HamanoJul 2, 2013

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.