[PATCH 2/2] submodule: Try harder to fetch needed sha1 by direct fetching sha1

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When reviewing a change in Gerrit, which also updates a submodule,
a common review practice is to download and cherry-pick the patch locally
to test it. However when testing it locally, the 'git submodule update'
may fail fetching the correct submodule sha1 as the corresponding commit
in the submodule is not yet part of the project history, but also just a
proposed change.

If $sha1 was not part of the default fetch, we try to fetch the $sha1
directly. Some servers however do not support direct fetch by sha1, which
leads git-fetch to fail quickly. We can fail ourselves here as the still
missing sha1 would lead to a failure later in the checkout stage anyway,
so failing here is as good as we can get.

Signed-off-by: Stefan Beller <sbeller@xxxxxxxxxx>
---

We may want to discuss the error message. It is the same as in the case
before (git-fetch <no args>), this is good for translation, but may be bad
for the user as we may want to give extra information.
("We fetched for you and it worked, however the sha1 was not included,
so we fetched again the server broke it, so we error out.  You used to
see error message: ....")

Although this may be too much information?

Thanks,
Stefan

 git-submodule.sh | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/git-submodule.sh b/git-submodule.sh
index f5d6675..f021fe3 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -749,6 +749,13 @@ Maybe you want to use 'update --init'?")"
 					( (rev=$(git rev-list --objects -n 1 $sha1 --not --all 2>/dev/null) &&
 					 test -z "$rev") || git-fetch)) ||
 				die "$(eval_gettext "Unable to fetch in submodule path '\$displaypath'")"
+
+				# In case the sha1 is still missing, try harder
+				# by fetching the sha1 directly.
+				(clear_local_git_env; cd "$sm_path" &&
+					( (rev=$(git rev-list --objects -n 1 $sha1 --not --all 2>/dev/null) &&
+					 test -z "$rev") || git-fetch $(get_default_remote) $sha1 )) ||
+				die "$(eval_gettext "Unable to fetch in submodule path '\$displaypath'")"
 			fi
 
 			# Is this something we just cloned?
-- 
2.7.0.rc0.34.ga06e0b3.dirty

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]