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

[PATCH] submodule update - don't run git-fetch if sha1 available

From
TSTorgil Svensson <torgil.svensson@gmail.com>
Date
Aug 11, 2007, 17:48 UTC
Message-ID
<e7bda7770708111048s77fbf416k9d0352486aee6b4a@mail.gmail.com>

It's un-necessary (both time-consuming and annoying if you are disconnected) for git submodule update to always running git-fetch prior to the detached head checkout of the submodule if the commit already exists.

Signed-off-by: Torgil Svensson <torgil.svensson@gmail.com>
---
 git-submodule.sh |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/git-submodule.sh b/git-submodule.sh
index 2cfeadd..dc2ed4b 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -39,6 +39,11 @@ get_repo_base() {
        ) 2>/dev/null
 }

+has_sha1()
+{
+       git rev-list 2>/dev/null --max-count=0 $1
+}
+
 #
 # Map submodule path to submodule name
 #
@@ -193,9 +198,9 @@ modules_update()

                if test "$subsha1" != "$sha1"
                then
-                       (unset GIT_DIR && cd "$path" && git-fetch &&
+                       (unset GIT_DIR && cd "$path" && (has_sha1
"$sha1" || git-fetch) &&
                                git-checkout -q "$sha1") ||
-                       die "Unable to checkout '$sha1' in submodule
path '$path'"
+                       die "Unable to checkout '$sha1' in submodule
path '$path'"

                        say "Submodule path '$path': checked out '$sha1'"
                fi
--
1.5.3.rc4.730.ga8c3-dirty
Next: Torgil Svensson
Message 1 of 7 in “submodule update - don't run git-fetch if sha1 available”
  1. submodule update - don't run git-fetch if sha1 availableTorgil Svensson, Aug 11, 2007
  2. Torgil SvenssonAug 11, 2007
  3. Junio C HamanoAug 11, 2007
  4. Torgil SvenssonAug 12, 2007
  5. Junio C HamanoAug 12, 2007
  6. Torgil SvenssonAug 19, 2007
  7. Junio C HamanoAug 19, 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.