Skip to content

Commit

Permalink
git-submodule: Fix "Unable to checkout" for the initial 'update'
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
pkufranky authored and spearce committed Sep 29, 2008
1 parent 2a79d2f commit b9b378a
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions git-submodule.sh
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ cmd_add()
else

module_clone "$path" "$realrepo" || exit
(unset GIT_DIR; cd "$path" && git checkout -q ${branch:+-b "$branch" "origin/$branch"}) ||
(unset GIT_DIR; cd "$path" && git checkout -f -q ${branch:+-b "$branch" "origin/$branch"}) ||
die "Unable to checkout submodule '$path'"
fi

Expand Down Expand Up @@ -311,8 +311,13 @@ cmd_update()

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

say "Submodule path '$path': checked out '$sha1'"
Expand Down

0 comments on commit b9b378a

Please sign in to comment.