Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
git-submodule: add support for --merge.
Browse files Browse the repository at this point in the history
'git submodule update --merge' merges the commit referenced by the
superproject into your local branch, instead of checking it out on
a detached HEAD.

As evidenced by the addition of "git submodule update --rebase", it
is useful to provide alternatives to the default 'checkout' behaviour
of "git submodule update". One such alternative is, when updating a
submodule to a new commit, to merge that commit into the current
local branch in that submodule. This is useful in workflows where
you want to update your submodule from its upstream, but you cannot
use --rebase, because you have downstream people working on top of
your submodule branch, and you don't want to disrupt their work.

Signed-off-by: Johan Herland <johan@herland.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
jherland authored and gitster committed Jun 3, 2009
1 parent 3294842 commit 42b4917
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 6 deletions.
15 changes: 13 additions & 2 deletions Documentation/git-submodule.txt
Expand Up @@ -113,8 +113,9 @@ init::
update::
Update the registered submodules, i.e. clone missing submodules and
checkout the commit specified in the index of the containing repository.
This will make the submodules HEAD be detached unless '--rebase' is
specified or the key `submodule.$name.update` is set to `rebase`.
This will make the submodules HEAD be detached unless '--rebase' or
'--merge' is specified or the key `submodule.$name.update` is set to
`rebase` or `merge`.
+
If the submodule is not yet initialized, and you just want to use the
setting as stored in .gitmodules, you can automatically initialize the
Expand Down Expand Up @@ -187,6 +188,16 @@ OPTIONS
If the key `submodule.$name.update` is set to `rebase`, this option is
implicit.

--merge::
This option is only valid for the update command.
Merge the commit recorded in the superproject into the current branch
of the submodule. If this option is given, the submodule's HEAD will
not be detached. If a merge failure prevents this process, you will
have to resolve the resulting conflicts within the submodule with the
usual conflict resolution tools.
If the key `submodule.$name.update` is set to `merge`, this option is
implicit.

<path>...::
Paths to submodule(s). When specified this will restrict the command
to only operate on the submodules found at the specified paths.
Expand Down
6 changes: 4 additions & 2 deletions Documentation/gitmodules.txt
Expand Up @@ -35,9 +35,11 @@ submodule.<name>.update::
If 'checkout' (the default), the new commit specified in the
superproject will be checked out in the submodule on a detached HEAD.
If 'rebase', the current branch of the submodule will be rebased onto
the commit specified in the superproject.
the commit specified in the superproject. If 'merge', the commit
specified in the superproject will be merged into the current branch
in the submodule.
This config option is overridden if 'git submodule update' is given
the '--rebase' option.
the '--merge' or '--rebase' options.


EXAMPLES
Expand Down
11 changes: 10 additions & 1 deletion git-submodule.sh
Expand Up @@ -5,7 +5,7 @@
# Copyright (c) 2007 Lars Hjemli

USAGE="[--quiet] [--cached] \
[add [-b branch] <repo> <path>]|[status|init|update [-i|--init] [-N|--no-fetch]|summary [-n|--summary-limit <n>] [<commit>]] \
[add [-b branch] <repo> <path>]|[status|init|update [-i|--init] [-N|--no-fetch] [--rebase|--merge]|summary [-n|--summary-limit <n>] [<commit>]] \
[--] [<path>...]|[foreach <command>]|[sync [--] [<path>...]]"
OPTIONS_SPEC=
. git-sh-setup
Expand Down Expand Up @@ -331,6 +331,10 @@ cmd_update()
shift
update="rebase"
;;
-m|--merge)
shift
update="merge"
;;
--)
shift
break
Expand Down Expand Up @@ -396,6 +400,11 @@ cmd_update()
action="rebase"
msg="rebased onto"
;;
merge)
command="git merge"
action="merge"
msg="merged in"
;;
*)
command="git checkout $force -q"
action="checkout"
Expand Down
60 changes: 59 additions & 1 deletion t/t7406-submodule-update.sh
Expand Up @@ -6,7 +6,7 @@
test_description='Test updating submodules
This test verifies that "git submodule update" detaches the HEAD of the
submodule and "git submodule update --rebase" does not detach the HEAD.
submodule and "git submodule update --rebase/--merge" does not detach the HEAD.
'

. ./test-lib.sh
Expand Down Expand Up @@ -76,6 +76,20 @@ test_expect_success 'submodule update --rebase staying on master' '
)
'

test_expect_success 'submodule update --merge staying on master' '
(cd super/submodule &&
git reset --hard HEAD~1
) &&
(cd super &&
(cd submodule &&
compare_head
) &&
git submodule update --merge submodule &&
cd submodule &&
compare_head
)
'

test_expect_success 'submodule update - rebase in .git/config' '
(cd super &&
git config submodule.submodule.update rebase
Expand Down Expand Up @@ -110,6 +124,40 @@ test_expect_success 'submodule update - checkout in .git/config but --rebase giv
)
'

test_expect_success 'submodule update - merge in .git/config' '
(cd super &&
git config submodule.submodule.update merge
) &&
(cd super/submodule &&
git reset --hard HEAD~1
) &&
(cd super &&
(cd submodule &&
compare_head
) &&
git submodule update submodule &&
cd submodule &&
compare_head
)
'

test_expect_success 'submodule update - checkout in .git/config but --merge given' '
(cd super &&
git config submodule.submodule.update checkout
) &&
(cd super/submodule &&
git reset --hard HEAD~1
) &&
(cd super &&
(cd submodule &&
compare_head
) &&
git submodule update --merge submodule &&
cd submodule &&
compare_head
)
'

test_expect_success 'submodule update - checkout in .git/config' '
(cd super &&
git config submodule.submodule.update checkout
Expand Down Expand Up @@ -137,4 +185,14 @@ test_expect_success 'submodule init picks up rebase' '
)
'

test_expect_success 'submodule init picks up merge' '
(cd super &&
git config submodule.merging.url git://non-existing/git &&
git config submodule.merging.path does-not-matter &&
git config submodule.merging.update merge &&
git submodule init merging &&
test "merge" = $(git config submodule.merging.update)
)
'

test_done

0 comments on commit 42b4917

Please sign in to comment.