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

Re: [PATCH] submodule: fix fetch_in_submodule logic

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 24, 2020, 21:13 UTC
Message-ID
<xmqqzh36ihkc.fsf@gitster.c.googlers.com>
In-Reply-To
<X7zM/d1CVuyCstZo@coredump.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 53 quoted lines
> This is a fix on top of ab/retire-parse-remote, which is now in next. I
> think submodule fetching is pretty broken, so we should do this or
> something like it soon.
>
> -- >8 --
> Commit 1c1518071c (submodule: use "fetch" logic instead of custom remote
> discovery, 2020-11-14) rewrote the logic in fetch_in_submodule to do:
>
>   elif test "$2" -ne ""
>
> But this is nonsense in shell: -ne is for numeric comparisons. This
> should be "=" or more idiomatically:
>
>   elif test -n "$2"
>
> But once we fix that, many tests start failing. Because that commit
> introduced another problem. The caller that passes 3 arguments looks
> like this:
>
>     fetch_in_submodule "$sm_path" $depth "$sha1"
>
> Note the unquoted $depth parameter. When it isn't set, the function will
> see only 2 arguments, and the function has no idea if what it sees in $2
> is an option to go on the command line, or a refspec to pass on stdin.
> In the old code before that commit:
>
>    fetch_in_submodule () (
>         sanitize_submodule_env &&
>         cd "$1" &&
>   -     case "$2" in
>   -     '')
>   -             git fetch ;;
>   -     *)
>   -             shift
>   -             git fetch $(get_default_remote) "$@" ;;
>   -     esac
>
> we treated those the same, so it didn't matter. But in the new logic
> (with my fix above):
>
>   +     if test $# -eq 3
>   +     then
>   +             echo "$3" | git fetch --stdin "$2"
>   +     elif test -n "$n"
>   +     then
>   +             git fetch "$2"
>   +     else
>   +             git fetch
>   +     fi
>
> we use the number of parameters to distinguish the two. Let's insist
> that the caller pass an empty string for positional parameter two if
> they want to have a third parameter after it.

Thanks for catching. I thought we stared at this part long enough to be updated between the rounds; it is embarrassing that we've missed it.

Show 5 quoted lines
>   - it probably wouldn't hurt to beef up the tests, especially around
>     fetching an unreachable sha1, but after getting lost for an hour in
>     the spaghetti of the submodule code and its tests, I gave up. I do
>     at least feel this code is being exercised (because once the initial
>     problem is fixed, tons of things fail).
True.
Show 18 quoted lines
> +# usage: fetch_in_submodule <module_path> [<depth>] [<sha1>]
> +# Because arguments are positional, use an empty string to omit <depth>
> +# but include <sha1>.
>  fetch_in_submodule () (
>  	sanitize_submodule_env &&
>  	cd "$1" &&
>  	if test $# -eq 3
>  	then
> -		echo "$3" | git fetch --stdin "$2"
> -	elif test "$2" -ne ""
> -	then
> -		git fetch "$2"
> +		echo "$3" | git fetch --stdin ${2:+"$2"}
>  	else
> -		git fetch
> +		git fetch ${2:+"$2"}
>  	fi
>  )
Makes sense.  Thanks.
Show 8 quoted lines
> @@ -603,7 +603,7 @@ cmd_update()
>  				# Now we tried the usual fetch, but $sha1 may
>  				# not be reachable from any of the refs
>  				is_tip_reachable "$sm_path" "$sha1" ||
> -				fetch_in_submodule "$sm_path" $depth "$sha1" ||
> +				fetch_in_submodule "$sm_path" "$depth" "$sha1" ||
>  				die "$(eval_gettext "Fetched in submodule path '\$displaypath', but it did not contain \$sha1. Direct fetching of that commit failed.")"
>  			fi
Previous: Jeff King
Message 2 of 2 in “submodule: fix fetch_in_submodule logic”
  1. submodule: fix fetch_in_submodule logicJeff King, Nov 24, 2020
  2. Junio C HamanoNov 24, 2020

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.