Skip to content

Commit b9b378a

Browse files
pkufrankyspearce
authored andcommitted
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>
1 parent 2a79d2f commit b9b378a

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

git-submodule.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ cmd_add()
185185
else
186186

187187
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"}) ||
189189
die "Unable to checkout submodule '$path'"
190190
fi
191191

@@ -311,8 +311,13 @@ cmd_update()
311311

312312
if test "$subsha1" != "$sha1"
313313
then
314+
force=
315+
if test -z "$subsha1"
316+
then
317+
force="-f"
318+
fi
314319
(unset GIT_DIR; cd "$path" && git-fetch &&
315-
git-checkout -q "$sha1") ||
320+
git-checkout $force -q "$sha1") ||
316321
die "Unable to checkout '$sha1' in submodule path '$path'"
317322

318323
say "Submodule path '$path': checked out '$sha1'"

0 commit comments

Comments
 (0)