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

Re: [PATCH] git-submodule.sh: avoid "test <cond> -a/-o <cond>"

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 10, 2014, 17:02 UTC
Message-ID
<xmqqegywaeb5.fsf@gitster.dls.corp.google.com>
In-Reply-To
<1402418594-1377-1-git-send-email-gitter.spiros@gmail.com>
Elia Pinto <gitter.spiros@gmail.com> writes:
Show 6 quoted lines
> @@ -832,7 +832,7 @@ Maybe you want to use 'update --init'?")"
>  			continue
>  		fi
>  
> -		if ! test -d "$sm_path"/.git -o -f "$sm_path"/.git
> +		if ! test -d "$sm_path"/.git && test -f "$sm_path"/.git
Hmmmm.  Is the above correct?
    $ if ! false && true; then echo true; else echo false; fi
    true

In other words, "! cmd1 && cmd2" parses not as "! (cmd1 && cmd2)" but as "(! cmd1) && cmd2".

It almost makes me wonder if the code may become simpler if we did it the way in the attached. That is, "if $sm_path/.git is there (whether as an embedded repository, or a file pointing to a repository elsewhere), then grab its HEAD, otherwise $sm_path is a submodule that hasn't been run 'submodule init' on, so run the whole nine yards starting from module_clone".

 git-submodule.sh | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/git-submodule.sh b/git-submodule.sh
index e146b83..018f1bb 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -832,15 +832,15 @@ Maybe you want to use 'update --init'?")"
 			continue
 		fi
 
-		if ! test -d "$sm_path"/.git -o -f "$sm_path"/.git
+		if test -e "$sm_path/.git"
 		then
-			module_clone "$sm_path" "$name" "$url" "$reference" "$depth" || exit
-			cloned_modules="$cloned_modules;$name"
-			subsha1=
-		else
 			subsha1=$(clear_local_git_env; cd "$sm_path" &&
 				git rev-parse --verify HEAD) ||
 			die "$(eval_gettext "Unable to find current revision in submodule path '\$displaypath'")"
+		else
+			module_clone "$sm_path" "$name" "$url" "$reference" "$depth" || exit
+			cloned_modules="$cloned_modules;$name"
+			subsha1=
 		fi
 
 		if test -n "$remote"
Previous: Elia PintoNext: Junio C Hamano
Message 2 of 4 in “git-submodule.sh: avoid "test <cond> -a/-o <cond>"”
  1. git-submodule.sh: avoid "test <cond> -a/-o <cond>"Elia Pinto, Jun 10, 2014
  2. Junio C HamanoJun 10, 2014
  3. Junio C HamanoJun 10, 2014
  4. Eric SunshineJun 10, 2014

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.