@matheusbsbs / matheus-bagliano / commits / e5f522d610
Fork 0

submodule update: Don't fetch when the submodule commit is already present

If the commit to be checked out on "git submodule update" has already been fetched in the submodule there is no need to run "git fetch" again. Since "git fetch" recently learned recursion (and the new on-demand mode to fetch commits recorded in the superproject is enabled by default) this will happen pretty often, thereby making the unconditional fetch during "git submodule update" unnecessary. If the commit is not present in the submodule (e.g. the user disabled the fetch on-demand mode) the fetch will be run as before. Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jens Lehmann committed Mar 6, 2011 at 23:13 UTC e5f522d610d34914e3fcf8b23de1b771c467196e
2 files changed +24 -1
git-submodule.sh
+4 -1
@@ -464,8 +464,11 @@ cmd_update()
464
465 if test -z "$nofetch"
466 then
467 + # Run fetch only if $sha1 isn't present or it
468 + # is not reachable from a ref.
469 (clear_local_git_env; cd "$path" &&
468 - git-fetch) ||
470 + ((rev=$(git rev-list -n 1 $sha1 --not --all 2>/dev/null) &&
471 + test -z "$rev") || git-fetch)) ||
472 die "Unable to fetch in submodule path '$path'"
473 fi
474
t/t7406-submodule-update.sh
+20
@@ -74,6 +74,26 @@ test_expect_success 'submodule update detaching the HEAD ' '
74 )
75 '
76
77 +apos="'";
78 +test_expect_success 'submodule update does not fetch already present commits' '
79 + (cd submodule &&
80 + echo line3 >> file &&
81 + git add file &&
82 + test_tick &&
83 + git commit -m "upstream line3"
84 + ) &&
85 + (cd super/submodule &&
86 + head=$(git rev-parse --verify HEAD) &&
87 + echo "Submodule path ${apos}submodule$apos: checked out $apos$head$apos" > ../../expected &&
88 + git reset --hard HEAD~1
89 + ) &&
90 + (cd super &&
91 + git submodule update > ../actual 2> ../actual.err
92 + ) &&
93 + test_cmp expected actual &&
94 + ! test -s actual.err
95 +'
96 +
97 test_expect_success 'submodule update --rebase staying on master' '
98 (cd super/submodule &&
99 git checkout master