Merge branch 'ph/submodule-rebase' (early part)
* 'ph/submodule-rebase' (early part): Rename submodule.<name>.rebase to submodule.<name>.update git-submodule: add support for --rebase. Conflicts: Documentation/git-submodule.txt git-submodule.shmaint
commit
7d40f89137
|
@ -13,7 +13,7 @@ SYNOPSIS
|
||||||
[--reference <repository>] [--] <repository> <path>
|
[--reference <repository>] [--] <repository> <path>
|
||||||
'git submodule' [--quiet] status [--cached] [--] [<path>...]
|
'git submodule' [--quiet] status [--cached] [--] [<path>...]
|
||||||
'git submodule' [--quiet] init [--] [<path>...]
|
'git submodule' [--quiet] init [--] [<path>...]
|
||||||
'git submodule' [--quiet] update [--init] [-N|--no-fetch]
|
'git submodule' [--quiet] update [--init] [-N|--no-fetch] [--rebase]
|
||||||
[--reference <repository>] [--] [<path>...]
|
[--reference <repository>] [--] [<path>...]
|
||||||
'git submodule' [--quiet] summary [--summary-limit <n>] [commit] [--] [<path>...]
|
'git submodule' [--quiet] summary [--summary-limit <n>] [commit] [--] [<path>...]
|
||||||
'git submodule' [--quiet] foreach <command>
|
'git submodule' [--quiet] foreach <command>
|
||||||
|
@ -115,7 +115,8 @@ init::
|
||||||
update::
|
update::
|
||||||
Update the registered submodules, i.e. clone missing submodules and
|
Update the registered submodules, i.e. clone missing submodules and
|
||||||
checkout the commit specified in the index of the containing repository.
|
checkout the commit specified in the index of the containing repository.
|
||||||
This will make the submodules HEAD be detached.
|
This will make the submodules HEAD be detached unless '--rebase' is
|
||||||
|
specified or the key `submodule.$name.update` is set to `rebase`.
|
||||||
+
|
+
|
||||||
If the submodule is not yet initialized, and you just want to use the
|
If the submodule is not yet initialized, and you just want to use the
|
||||||
setting as stored in .gitmodules, you can automatically initialize the
|
setting as stored in .gitmodules, you can automatically initialize the
|
||||||
|
@ -179,6 +180,15 @@ OPTIONS
|
||||||
This option is only valid for the update command.
|
This option is only valid for the update command.
|
||||||
Don't fetch new objects from the remote site.
|
Don't fetch new objects from the remote site.
|
||||||
|
|
||||||
|
--rebase::
|
||||||
|
This option is only valid for the update command.
|
||||||
|
Rebase the current branch onto the commit recorded in the
|
||||||
|
superproject. If this option is given, the submodule's HEAD will not
|
||||||
|
be detached. If a a merge failure prevents this process, you will have
|
||||||
|
to resolve these failures with linkgit:git-rebase[1].
|
||||||
|
If the key `submodule.$name.update` is set to `rebase`, this option is
|
||||||
|
implicit.
|
||||||
|
|
||||||
--reference <repository>::
|
--reference <repository>::
|
||||||
This option is only valid for add and update commands. These
|
This option is only valid for add and update commands. These
|
||||||
commands sometimes need to clone a remote repository. In this case,
|
commands sometimes need to clone a remote repository. In this case,
|
||||||
|
|
|
@ -30,6 +30,15 @@ submodule.<name>.path::
|
||||||
submodule.<name>.url::
|
submodule.<name>.url::
|
||||||
Defines an url from where the submodule repository can be cloned.
|
Defines an url from where the submodule repository can be cloned.
|
||||||
|
|
||||||
|
submodule.<name>.update::
|
||||||
|
Defines what to do when the submodule is updated by the superproject.
|
||||||
|
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.
|
||||||
|
This config option is overridden if 'git submodule update' is given
|
||||||
|
the '--rebase' option.
|
||||||
|
|
||||||
|
|
||||||
EXAMPLES
|
EXAMPLES
|
||||||
--------
|
--------
|
||||||
|
|
|
@ -18,6 +18,7 @@ quiet=
|
||||||
reference=
|
reference=
|
||||||
cached=
|
cached=
|
||||||
nofetch=
|
nofetch=
|
||||||
|
update=
|
||||||
|
|
||||||
#
|
#
|
||||||
# print stuff on stdout unless -q was specified
|
# print stuff on stdout unless -q was specified
|
||||||
|
@ -310,6 +311,11 @@ cmd_init()
|
||||||
git config submodule."$name".url "$url" ||
|
git config submodule."$name".url "$url" ||
|
||||||
die "Failed to register url for submodule path '$path'"
|
die "Failed to register url for submodule path '$path'"
|
||||||
|
|
||||||
|
upd="$(git config -f .gitmodules submodule."$name".update)"
|
||||||
|
test -z "$upd" ||
|
||||||
|
git config submodule."$name".update "$upd" ||
|
||||||
|
die "Failed to register update mode for submodule path '$path'"
|
||||||
|
|
||||||
say "Submodule '$name' ($url) registered for path '$path'"
|
say "Submodule '$name' ($url) registered for path '$path'"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
@ -337,6 +343,10 @@ cmd_update()
|
||||||
shift
|
shift
|
||||||
nofetch=1
|
nofetch=1
|
||||||
;;
|
;;
|
||||||
|
-r|--rebase)
|
||||||
|
shift
|
||||||
|
update="rebase"
|
||||||
|
;;
|
||||||
--reference)
|
--reference)
|
||||||
case "$2" in '') usage ;; esac
|
case "$2" in '') usage ;; esac
|
||||||
reference="--reference=$2"
|
reference="--reference=$2"
|
||||||
|
@ -369,6 +379,7 @@ cmd_update()
|
||||||
do
|
do
|
||||||
name=$(module_name "$path") || exit
|
name=$(module_name "$path") || exit
|
||||||
url=$(git config submodule."$name".url)
|
url=$(git config submodule."$name".url)
|
||||||
|
update_module=$(git config submodule."$name".update)
|
||||||
if test -z "$url"
|
if test -z "$url"
|
||||||
then
|
then
|
||||||
# Only mention uninitialized submodules when its
|
# Only mention uninitialized submodules when its
|
||||||
|
@ -389,6 +400,11 @@ cmd_update()
|
||||||
die "Unable to find current revision in submodule path '$path'"
|
die "Unable to find current revision in submodule path '$path'"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if ! test -z "$update"
|
||||||
|
then
|
||||||
|
update_module=$update
|
||||||
|
fi
|
||||||
|
|
||||||
if test "$subsha1" != "$sha1"
|
if test "$subsha1" != "$sha1"
|
||||||
then
|
then
|
||||||
force=
|
force=
|
||||||
|
@ -404,11 +420,22 @@ cmd_update()
|
||||||
die "Unable to fetch in submodule path '$path'"
|
die "Unable to fetch in submodule path '$path'"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
(unset GIT_DIR; cd "$path" &&
|
case "$update_module" in
|
||||||
git-checkout $force -q "$sha1") ||
|
rebase)
|
||||||
die "Unable to checkout '$sha1' in submodule path '$path'"
|
command="git rebase"
|
||||||
|
action="rebase"
|
||||||
|
msg="rebased onto"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
command="git checkout $force -q"
|
||||||
|
action="checkout"
|
||||||
|
msg="checked out"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
say "Submodule path '$path': checked out '$sha1'"
|
(unset GIT_DIR; cd "$path" && $command "$sha1") ||
|
||||||
|
die "Unable to $action '$sha1' in submodule path '$path'"
|
||||||
|
say "Submodule path '$path': $msg '$sha1'"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,140 @@
|
||||||
|
#!/bin/sh
|
||||||
|
#
|
||||||
|
# Copyright (c) 2009 Red Hat, Inc.
|
||||||
|
#
|
||||||
|
|
||||||
|
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.
|
||||||
|
'
|
||||||
|
|
||||||
|
. ./test-lib.sh
|
||||||
|
|
||||||
|
|
||||||
|
compare_head()
|
||||||
|
{
|
||||||
|
sha_master=`git-rev-list --max-count=1 master`
|
||||||
|
sha_head=`git-rev-list --max-count=1 HEAD`
|
||||||
|
|
||||||
|
test "$sha_master" = "$sha_head"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
test_expect_success 'setup a submodule tree' '
|
||||||
|
echo file > file &&
|
||||||
|
git add file &&
|
||||||
|
test_tick &&
|
||||||
|
git commit -m upstream
|
||||||
|
git clone . super &&
|
||||||
|
git clone super submodule &&
|
||||||
|
(cd super &&
|
||||||
|
git submodule add ../submodule submodule &&
|
||||||
|
test_tick &&
|
||||||
|
git commit -m "submodule" &&
|
||||||
|
git submodule init submodule
|
||||||
|
) &&
|
||||||
|
(cd submodule &&
|
||||||
|
echo "line2" > file &&
|
||||||
|
git add file &&
|
||||||
|
git commit -m "Commit 2"
|
||||||
|
) &&
|
||||||
|
(cd super &&
|
||||||
|
(cd submodule &&
|
||||||
|
git pull --rebase origin
|
||||||
|
) &&
|
||||||
|
git add submodule &&
|
||||||
|
git commit -m "submodule update"
|
||||||
|
)
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'submodule update detaching the HEAD ' '
|
||||||
|
(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 --rebase staying on master' '
|
||||||
|
(cd super/submodule &&
|
||||||
|
git checkout master
|
||||||
|
) &&
|
||||||
|
(cd super &&
|
||||||
|
(cd submodule &&
|
||||||
|
compare_head
|
||||||
|
) &&
|
||||||
|
git submodule update --rebase submodule &&
|
||||||
|
cd submodule &&
|
||||||
|
compare_head
|
||||||
|
)
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'submodule update - rebase in .git/config' '
|
||||||
|
(cd super &&
|
||||||
|
git config submodule.submodule.update rebase
|
||||||
|
) &&
|
||||||
|
(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 --rebase 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 --rebase submodule &&
|
||||||
|
cd submodule &&
|
||||||
|
compare_head
|
||||||
|
)
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'submodule update - checkout in .git/config' '
|
||||||
|
(cd super &&
|
||||||
|
git config submodule.submodule.update checkout
|
||||||
|
) &&
|
||||||
|
(cd super/submodule &&
|
||||||
|
git reset --hard HEAD^
|
||||||
|
) &&
|
||||||
|
(cd super &&
|
||||||
|
(cd submodule &&
|
||||||
|
compare_head
|
||||||
|
) &&
|
||||||
|
git submodule update submodule &&
|
||||||
|
cd submodule &&
|
||||||
|
! compare_head
|
||||||
|
)
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'submodule init picks up rebase' '
|
||||||
|
(cd super &&
|
||||||
|
git config submodule.rebasing.url git://non-existing/git &&
|
||||||
|
git config submodule.rebasing.path does-not-matter &&
|
||||||
|
git config submodule.rebasing.update rebase &&
|
||||||
|
git submodule init rebasing &&
|
||||||
|
test "rebase" = $(git config submodule.rebasing.update)
|
||||||
|
)
|
||||||
|
'
|
||||||
|
|
||||||
|
test_done
|
Loading…
Reference in New Issue