Merge branch 'nm/submodule-update-force'
* nm/submodule-update-force: submodule: Add --force option for git submodule update Conflicts: t/t7406-submodule-update.sh
This commit is contained in:
@ -186,8 +186,10 @@ OPTIONS
|
|||||||
|
|
||||||
-f::
|
-f::
|
||||||
--force::
|
--force::
|
||||||
This option is only valid for the add command.
|
This option is only valid for add and update commands.
|
||||||
Allow adding an otherwise ignored submodule path.
|
When running add, allow adding an otherwise ignored submodule path.
|
||||||
|
When running update, throw away local changes in submodules when
|
||||||
|
switching to a different commit.
|
||||||
|
|
||||||
--cached::
|
--cached::
|
||||||
This option is only valid for status and summary commands. These
|
This option is only valid for status and summary commands. These
|
||||||
|
@ -8,7 +8,7 @@ dashless=$(basename "$0" | sed -e 's/-/ /')
|
|||||||
USAGE="[--quiet] add [-b branch] [-f|--force] [--reference <repository>] [--] <repository> [<path>]
|
USAGE="[--quiet] add [-b branch] [-f|--force] [--reference <repository>] [--] <repository> [<path>]
|
||||||
or: $dashless [--quiet] status [--cached] [--recursive] [--] [<path>...]
|
or: $dashless [--quiet] status [--cached] [--recursive] [--] [<path>...]
|
||||||
or: $dashless [--quiet] init [--] [<path>...]
|
or: $dashless [--quiet] init [--] [<path>...]
|
||||||
or: $dashless [--quiet] update [--init] [-N|--no-fetch] [--rebase] [--reference <repository>] [--merge] [--recursive] [--] [<path>...]
|
or: $dashless [--quiet] update [--init] [-N|--no-fetch] [-f|--force] [--rebase] [--reference <repository>] [--merge] [--recursive] [--] [<path>...]
|
||||||
or: $dashless [--quiet] summary [--cached|--files] [--summary-limit <n>] [commit] [--] [<path>...]
|
or: $dashless [--quiet] summary [--cached|--files] [--summary-limit <n>] [commit] [--] [<path>...]
|
||||||
or: $dashless [--quiet] foreach [--recursive] <command>
|
or: $dashless [--quiet] foreach [--recursive] <command>
|
||||||
or: $dashless [--quiet] sync [--] [<path>...]"
|
or: $dashless [--quiet] sync [--] [<path>...]"
|
||||||
@ -402,6 +402,9 @@ cmd_update()
|
|||||||
-N|--no-fetch)
|
-N|--no-fetch)
|
||||||
nofetch=1
|
nofetch=1
|
||||||
;;
|
;;
|
||||||
|
-f|--force)
|
||||||
|
force=$1
|
||||||
|
;;
|
||||||
-r|--rebase)
|
-r|--rebase)
|
||||||
update="rebase"
|
update="rebase"
|
||||||
;;
|
;;
|
||||||
@ -480,10 +483,11 @@ cmd_update()
|
|||||||
|
|
||||||
if test "$subsha1" != "$sha1"
|
if test "$subsha1" != "$sha1"
|
||||||
then
|
then
|
||||||
force=
|
subforce=$force
|
||||||
if test -z "$subsha1"
|
# If we don't already have a -f flag and the submodule has never been checked out
|
||||||
|
if test -z "$subsha1" -a -z "$force"
|
||||||
then
|
then
|
||||||
force="-f"
|
subforce="-f"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if test -z "$nofetch"
|
if test -z "$nofetch"
|
||||||
@ -515,7 +519,7 @@ cmd_update()
|
|||||||
msg="merged in"
|
msg="merged in"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
command="git checkout $force -q"
|
command="git checkout $subforce -q"
|
||||||
action="checkout"
|
action="checkout"
|
||||||
msg="checked out"
|
msg="checked out"
|
||||||
;;
|
;;
|
||||||
|
@ -94,6 +94,29 @@ test_expect_success 'submodule update does not fetch already present commits' '
|
|||||||
! test -s actual.err
|
! test -s actual.err
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'submodule update should fail due to local changes' '
|
||||||
|
(cd super/submodule &&
|
||||||
|
git reset --hard HEAD~1 &&
|
||||||
|
echo "local change" > file
|
||||||
|
) &&
|
||||||
|
(cd super &&
|
||||||
|
(cd submodule &&
|
||||||
|
compare_head
|
||||||
|
) &&
|
||||||
|
test_must_fail git submodule update submodule
|
||||||
|
)
|
||||||
|
'
|
||||||
|
test_expect_success 'submodule update should throw away changes with --force ' '
|
||||||
|
(cd super &&
|
||||||
|
(cd submodule &&
|
||||||
|
compare_head
|
||||||
|
) &&
|
||||||
|
git submodule update --force submodule &&
|
||||||
|
cd submodule &&
|
||||||
|
! compare_head
|
||||||
|
)
|
||||||
|
'
|
||||||
|
|
||||||
test_expect_success 'submodule update --rebase staying on master' '
|
test_expect_success 'submodule update --rebase staying on master' '
|
||||||
(cd super/submodule &&
|
(cd super/submodule &&
|
||||||
git checkout master
|
git checkout master
|
||||||
|
Reference in New Issue
Block a user