summaryrefslogtreecommitdiff
path: root/submodule.c
diff options
context:
space:
mode:
authorStefan Beller <sbeller@google.com>2017-06-23 19:13:02 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-06-23 22:36:53 (GMT)
commita6d7eb2c7a6a402a938824bcf1c5f331dd1a06bb (patch)
treeaf56f09949eb1808fcd1d0afdac78e23b38c6230 /submodule.c
parent8c69832d137042a4368248a995bebcc5b964a87b (diff)
downloadgit-a6d7eb2c7a6a402a938824bcf1c5f331dd1a06bb.zip
git-a6d7eb2c7a6a402a938824bcf1c5f331dd1a06bb.tar.gz
git-a6d7eb2c7a6a402a938824bcf1c5f331dd1a06bb.tar.bz2
pull: optionally rebase submodules (remote submodule changes only)
Teach pull to optionally update submodules when '--recurse-submodules' is provided. This will teach pull to run 'submodule update --rebase' when the '--recurse-submodules' and '--rebase' flags are given under specific circumstances. On a rebase workflow: ===================== 1. Both sides change the submodule ------------------------------ Let's assume the following history in a submodule: H---I---J---K---L local branch \ M---N---O---P remote branch and the following in the superproject (recorded submodule in parens): A(H)---B(I)---F(K)---G(L) local branch \ C(N)---D(N)---E(P) remote branch In an ideal world this would rebase the submodule and rewrite the submodule pointers that the superproject points at such that the superproject looks like A(H)---B(I) F(K')---G(L') rebased branch \ / C(N)---D(N)---E(P) remote branch and the submodule as: J---K---L (old dangeling tip) / H---I J'---K'---L' rebased branch \ / M---N---O---P remote branch And if a conflict arises in the submodule the superproject rebase would stop at that commit at which the submodule conflict occurs. Currently a "pull --rebase" in the superproject produces a merge conflict as the submodule pointer changes are conflicting and cannot be resolved. 2. Local submodule changes only ----------------------- Assuming histories as above, except that the remote branch would not contain submodule changes, then a result as A(H)---B(I) F(K)---G(L) rebased branch \ / C(I)---D(I)---E(I) remote branch is desire-able. This is what currently happens in rebase. If the recursive flag is given, the ideal git would produce a superproject as: A(H)---B(I) F(K')---G(L') rebased branch (incl. sub rebase!) \ / C(I)---D(I)---E(I) remote branch and the submodule as: J---K---L (old dangeling tip) / H---I J'---K'---L' locally rebased branch \ / M---N---O---P advanced branch This patch doesn't address this issue, however a test is added that this fails up front. 3. Remote submodule changes only ---------------------- Assuming histories as in (1) except that the local superproject branch would not have touched the submodule the rebase already works out in the superproject with no conflicts: A(H)---B(I) F(P)---G(P) rebased branch (no sub changes) \ / C(N)---D(N)---E(P) remote branch The recurse flag as presented in this patch would additionally update the submodule as: H---I J'---K'---L' rebased branch \ / M---N---O---P remote branch As neither J, K, L nor J', K', L' are referred to from the superproject, no rewriting of the superproject commits is required. Conclusion for 'pull --rebase --recursive' ----------------------------------------- If there are no local superproject changes it is sufficient to call "submodule update --rebase" as this produces the desired results. In case of conflicts, the behavior is the same as in 'submodule update --recursive' which is assumed to be sane. This patch implements (3) only. On a merge workflow: ==================== We'll start off with the same underlying DAG as in (1) in the rebase workflow. So in an ideal world a 'pull --merge --recursive' would produce this: H---I---J---K---L----X \ / M---N---O---P with X as the new merge-commit in the submodule and the superproject as: A(H)---B(I)---F(K)---G(L)---Y(X) \ / C(N)---D(N)---E(P) However modifying the submodules on the fly is not supported in git-merge such that Y(X) is not easy to produce in a single patch. In fact git-merge doesn't know about submodules at all. However when at least one side does not contain commits touching the submodule at all, then we do not need to perform the merge for the submodule but a fast-forward can be done via checking out either L or P in the submodule. This strategy is implemented in 68d03e4a6e (Implement automatic fast-forward merge for submodules, 2010-07-07) already, so to align with the rebase behavior we need to also update the worktree of the submodule. Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'submodule.c')
-rw-r--r--submodule.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/submodule.c b/submodule.c
index 1b8a3b5..6e2e35a 100644
--- a/submodule.c
+++ b/submodule.c
@@ -1126,6 +1126,32 @@ static void calculate_changed_submodule_paths(void)
initialized_fetch_ref_tips = 0;
}
+int submodule_touches_in_range(struct object_id *excl_oid,
+ struct object_id *incl_oid)
+{
+ struct string_list subs = STRING_LIST_INIT_DUP;
+ struct argv_array args = ARGV_ARRAY_INIT;
+ int ret;
+
+ gitmodules_config();
+ /* No need to check if there are no submodules configured */
+ if (!submodule_from_path(NULL, NULL))
+ return 0;
+
+ argv_array_push(&args, "--"); /* args[0] program name */
+ argv_array_push(&args, oid_to_hex(incl_oid));
+ argv_array_push(&args, "--not");
+ argv_array_push(&args, oid_to_hex(excl_oid));
+
+ collect_changed_submodules(&subs, &args);
+ ret = subs.nr;
+
+ argv_array_clear(&args);
+
+ free_submodules_oids(&subs);
+ return ret;
+}
+
struct submodule_parallel_fetch {
int count;
struct argv_array args;