git/builtin
Stefan Beller a6d7eb2c7a 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>
2017-06-23 15:36:53 -07:00
..
add.c Merge branch 'bw/pathspec-sans-the-index' 2017-05-30 11:16:40 +09:00
am.c Merge branch 'bw/object-id' 2017-06-19 12:38:44 -07:00
annotate.c
apply.c Convert read_mmblob to take struct object_id. 2016-09-07 12:59:42 -07:00
archive.c archive: read local configuration 2016-11-22 13:55:20 -08:00
bisect--helper.c
blame.c Merge branch 'nd/fopen-errors' 2017-06-13 13:47:09 -07:00
branch.c Convert lookup_commit* to struct object_id 2017-05-08 15:12:57 +09:00
bundle.c bundle: use prefix_filename with bundle path 2017-03-21 11:18:41 -07:00
cat-file.c Merge branch 'js/blame-lib' 2017-06-05 09:18:12 +09:00
check-attr.c attr: tighten const correctness with git_attr and match_attr 2017-02-01 13:46:53 -08:00
check-ignore.c Merge branch 'bw/pathspec-sans-the-index' 2017-05-30 11:16:40 +09:00
check-mailmap.c strbuf: introduce strbuf_getline_{lf,nul}() 2016-01-15 10:12:51 -08:00
check-ref-format.c use xmallocz to avoid size arithmetic 2016-02-22 14:51:09 -08:00
checkout-index.c hold_locked_index(): align error handling with hold_lockfile_for_update() 2016-12-07 11:31:59 -08:00
checkout.c Merge branch 'sb/submodule-blanket-recursive' 2017-06-13 13:47:07 -07:00
clean.c Merge branch 'sl/clean-d-ignored-fix' 2017-06-02 15:06:05 +09:00
clone.c Merge branch 'nd/fopen-errors' 2017-06-13 13:47:09 -07:00
column.c column: read lines with strbuf_getline() 2016-01-15 10:35:07 -08:00
commit-tree.c Convert lookup_commit* to struct object_id 2017-05-08 15:12:57 +09:00
commit.c Merge branch 'bw/object-id' 2017-06-19 12:38:44 -07:00
config.c config: complain about --local outside of a git repo 2017-05-15 11:30:51 +09:00
count-objects.c Convert object iteration callbacks to struct object_id 2017-02-22 10:12:15 -08:00
credential.c credential: handle invalid arguments earlier 2017-05-30 14:45:03 +09:00
describe.c Convert lookup_tag to struct object_id 2017-05-08 15:12:57 +09:00
diff-files.c Merge branch 'jk/consistent-h' 2017-06-19 12:38:45 -07:00
diff-index.c Merge branch 'jk/consistent-h' 2017-06-19 12:38:45 -07:00
diff-tree.c Merge branch 'jk/consistent-h' 2017-06-19 12:38:45 -07:00
diff.c Merge branch 'bw/object-id' 2017-06-19 12:38:44 -07:00
difftool.c difftool: address a couple of resource/memory leaks 2017-05-08 12:18:19 +09:00
fast-export.c Merge branch 'bw/object-id' 2017-06-19 12:38:44 -07:00
fetch-pack.c Rename sha1_array to oid_array 2017-03-31 08:33:56 -07:00
fetch.c builtin/fetch: parse recurse-submodules-default at default options parsing 2017-06-23 15:36:24 -07:00
fmt-merge-msg.c object: convert parse_object* to take struct object_id 2017-05-08 15:12:58 +09:00
for-each-ref.c ref-filter: add --no-contains option to tag/branch/for-each-ref 2017-03-24 12:15:26 -07:00
fsck.c Merge branch 'nd/fopen-errors' 2017-06-13 13:47:09 -07:00
gc.c Merge branch 'js/larger-timestamps' 2017-05-16 11:51:59 +09:00
get-tar-commit-id.c usage: do not insist that standard input must come from a file 2015-10-16 15:27:52 -07:00
grep.c Merge branch 'bw/object-id' 2017-06-19 12:38:44 -07:00
hash-object.c prefix_filename: return newly allocated string 2017-03-21 11:18:41 -07:00
help.c Merge branch 'js/no-html-bypass-on-windows' into maint 2016-09-08 21:35:55 -07:00
index-pack.c object: convert parse_object* to take struct object_id 2017-05-08 15:12:58 +09:00
init-db.c real_pathdup(): fix callsites that wanted it to die on error 2017-03-08 14:38:41 -08:00
interpret-trailers.c Merge branch 'jk/parseopt-string-list' into jk/string-list-static-init 2016-06-13 10:37:48 -07:00
log.c Merge branch 'bw/object-id' 2017-06-19 12:38:44 -07:00
ls-files.c Merge branch 'bw/pathspec-sans-the-index' 2017-05-30 11:16:40 +09:00
ls-remote.c avoid using fixed PATH_MAX buffers for refs 2017-03-30 14:59:50 -07:00
ls-tree.c tree: convert parse_tree_indirect to struct object_id 2017-05-08 15:12:58 +09:00
mailinfo.c prefix_filename: return newly allocated string 2017-03-21 11:18:41 -07:00
mailsplit.c mailinfo & mailsplit: check for EOF while parsing 2017-05-08 12:18:19 +09:00
merge-base.c Merge branch 'bc/object-id' 2017-05-29 12:34:43 +09:00
merge-file.c prefix_filename: return newly allocated string 2017-03-21 11:18:41 -07:00
merge-index.c Convert GIT_SHA1_HEXSZ used for allocation to GIT_MAX_HEXSZ 2017-03-26 22:08:21 -07:00
merge-ours.c
merge-recursive.c i18n: merge-recursive: mark verbose message for translation 2016-09-15 13:17:32 -07:00
merge-tree.c Convert lookup_blob to struct object_id 2017-05-08 15:12:57 +09:00
merge.c Merge branch 'bw/object-id' 2017-06-19 12:38:44 -07:00
mktag.c usage: do not insist that standard input must come from a file 2015-10-16 15:27:52 -07:00
mktree.c mktree: plug memory leaks reported by Coverity 2017-05-08 12:18:19 +09:00
mv.c Merge branch 'bw/pathspec-cleanup' 2017-01-18 15:12:15 -08:00
name-rev.c Merge branch 'js/larger-timestamps' 2017-05-30 11:16:45 +09:00
notes.c Merge branch 'bw/object-id' 2017-06-19 12:38:44 -07:00
pack-objects.c Merge branch 'ab/grep-preparatory-cleanup' 2017-06-02 15:06:06 +09:00
pack-redundant.c pack-redundant: plug memory leak 2017-05-08 12:18:19 +09:00
pack-refs.c refs: delete pack_refs() in favor of refs_pack_refs() 2017-04-14 03:53:25 -07:00
patch-id.c Convert GIT_SHA1_RAWSZ used for allocation to GIT_MAX_RAWSZ 2017-03-26 22:08:21 -07:00
prune-packed.c Convert object iteration callbacks to struct object_id 2017-02-22 10:12:15 -08:00
prune.c Merge branch 'bc/object-id' 2017-05-29 12:34:43 +09:00
pull.c pull: optionally rebase submodules (remote submodule changes only) 2017-06-23 15:36:53 -07:00
push.c builtin/push.c: respect 'submodule.recurse' option 2017-06-01 10:36:36 +09:00
read-tree.c Merge branch 'sb/submodule-blanket-recursive' 2017-06-13 13:47:07 -07:00
rebase--helper.c rebase--helper: add a builtin helper for interactive rebases 2017-02-09 14:55:26 -08:00
receive-pack.c Merge branch 'js/plug-leaks' 2017-05-29 12:34:44 +09:00
reflog.c Merge branch 'bc/object-id' 2017-05-29 12:34:43 +09:00
remote-ext.c remote-{ext,fd}: print usage message on invalid arguments 2017-05-30 14:45:04 +09:00
remote-fd.c remote-{ext,fd}: print usage message on invalid arguments 2017-05-30 14:45:04 +09:00
remote.c Merge branch 'mh/packed-ref-store-prep' 2017-06-05 09:18:11 +09:00
repack.c repack: accept --threads=<n> and pass it down to pack-objects 2017-04-27 08:09:25 +09:00
replace.c Convert lookup_tag to struct object_id 2017-05-08 15:12:57 +09:00
rerere.c Sync with 2.6.1 2015-10-05 13:20:08 -07:00
reset.c Merge branch 'sb/submodule-blanket-recursive' 2017-06-13 13:47:07 -07:00
rev-list.c Merge branch 'jk/consistent-h' 2017-06-19 12:38:45 -07:00
rev-parse.c Merge branch 'bc/object-id' 2017-05-29 12:34:43 +09:00
revert.c Merge branch 'jk/cherry-pick-0-mainline' 2017-03-17 13:50:28 -07:00
rm.c Merge branch 'jc/noent-notdir' 2017-06-13 13:47:07 -07:00
send-pack.c Merge branch 'bc/object-id' 2017-04-19 21:37:13 -07:00
shortlog.c Merge branch 'rs/shortlog-cleanup' 2017-03-24 13:07:37 -07:00
show-branch.c Merge branch 'pc/dir-count-slashes' 2017-06-22 14:15:21 -07:00
show-ref.c show-ref: remove a stale comment 2017-01-23 18:51:56 -08:00
stripspace.c stripspace: respect repository config 2016-11-21 11:00:38 -08:00
submodule--helper.c Merge branch 'jk/consistent-h' 2017-06-19 12:38:45 -07:00
symbolic-ref.c delete_ref: accept a reflog message argument 2017-02-20 22:04:47 -08:00
tag.c Merge branch 'bc/object-id' 2017-05-29 12:34:43 +09:00
unpack-file.c convert trivial sprintf / strcpy calls to xsnprintf 2015-09-25 10:18:18 -07:00
unpack-objects.c object: convert parse_object* to take struct object_id 2017-05-08 15:12:58 +09:00
update-index.c Merge branch 'jc/noent-notdir' 2017-06-13 13:47:07 -07:00
update-ref.c update-ref: pass reflog message to delete_ref() 2017-02-20 22:04:47 -08:00
update-server-info.c
upload-archive.c upload-archive: handle "-h" option early 2017-05-30 14:45:04 +09:00
var.c
verify-commit.c Convert lookup_commit* to struct object_id 2017-05-08 15:12:57 +09:00
verify-pack.c
verify-tag.c builtin/verify-tag: add --format to verify-tag 2017-01-17 16:10:22 -08:00
worktree.c Merge branch 'js/plug-leaks' 2017-05-29 12:34:44 +09:00
write-tree.c