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

git-submodule: Fix "Unable to checkout" for the initial 'update'

Since commit 55218("checkout: do not lose staged removal"), in cmd_add/cmd_update, "git checkout <commit>" following "git clone -n" may fail if <commit> is different from HEAD. So Use "git checkout -f <commit>" to fix this. Signed-off-by: Ping Yin <pkufranky@gmail.com> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Ping Yin committed Sep 26, 2008 at 23:33 UTC b9b378a001d35a64a30a652a45f8084ee2be6cdf
1 file changed +7 -2
git-submodule.sh
+7 -2
@@ -185,7 +185,7 @@ cmd_add()
185 else
186
187 module_clone "$path" "$realrepo" || exit
188 - (unset GIT_DIR; cd "$path" && git checkout -q ${branch:+-b "$branch" "origin/$branch"}) ||
188 + (unset GIT_DIR; cd "$path" && git checkout -f -q ${branch:+-b "$branch" "origin/$branch"}) ||
189 die "Unable to checkout submodule '$path'"
190 fi
191
@@ -311,8 +311,13 @@ cmd_update()
311
312 if test "$subsha1" != "$sha1"
313 then
314 + force=
315 + if test -z "$subsha1"
316 + then
317 + force="-f"
318 + fi
319 (unset GIT_DIR; cd "$path" && git-fetch &&
315 - git-checkout -q "$sha1") ||
320 + git-checkout $force -q "$sha1") ||
321 die "Unable to checkout '$sha1' in submodule path '$path'"
322
323 say "Submodule path '$path': checked out '$sha1'"