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>
5 files changed
tree: af56f09949eb1808fcd1d0afdac78e23b38c6230
  1. .github/
  2. block-sha1/
  3. builtin/
  4. ci/
  5. compat/
  6. contrib/
  7. Documentation/
  8. ewah/
  9. git-gui/
  10. gitk-git/
  11. gitweb/
  12. mergetools/
  13. perl/
  14. po/
  15. ppc/
  16. refs/
  17. sha1dc/
  18. t/
  19. templates/
  20. vcs-svn/
  21. xdiff/
  22. .gitattributes
  23. .gitignore
  24. .mailmap
  25. .travis.yml
  26. abspath.c
  27. aclocal.m4
  28. advice.c
  29. advice.h
  30. alias.c
  31. alloc.c
  32. apply.c
  33. apply.h
  34. archive-tar.c
  35. archive-zip.c
  36. archive.c
  37. archive.h
  38. argv-array.c
  39. argv-array.h
  40. attr.c
  41. attr.h
  42. base85.c
  43. bisect.c
  44. bisect.h
  45. blame.c
  46. blame.h
  47. blob.c
  48. blob.h
  49. branch.c
  50. branch.h
  51. builtin.h
  52. bulk-checkin.c
  53. bulk-checkin.h
  54. bundle.c
  55. bundle.h
  56. cache-tree.c
  57. cache-tree.h
  58. cache.h
  59. check-builtins.sh
  60. check-racy.c
  61. check_bindir
  62. color.c
  63. color.h
  64. column.c
  65. column.h
  66. combine-diff.c
  67. command-list.txt
  68. commit-slab.h
  69. commit.c
  70. commit.h
  71. common-main.c
  72. config.c
  73. config.mak.in
  74. config.mak.uname
  75. configure.ac
  76. connect.c
  77. connect.h
  78. connected.c
  79. connected.h
  80. convert.c
  81. convert.h
  82. copy.c
  83. COPYING
  84. credential-cache--daemon.c
  85. credential-cache.c
  86. credential-store.c
  87. credential.c
  88. credential.h
  89. csum-file.c
  90. csum-file.h
  91. ctype.c
  92. daemon.c
  93. date.c
  94. decorate.c
  95. decorate.h
  96. delta.h
  97. diff-delta.c
  98. diff-lib.c
  99. diff-no-index.c
  100. diff.c
  101. diff.h
  102. diffcore-break.c
  103. diffcore-delta.c
  104. diffcore-order.c
  105. diffcore-pickaxe.c
  106. diffcore-rename.c
  107. diffcore.h
  108. dir-iterator.c
  109. dir-iterator.h
  110. dir.c
  111. dir.h
  112. editor.c
  113. entry.c
  114. environment.c
  115. exec_cmd.c
  116. exec_cmd.h
  117. fast-import.c
  118. fetch-pack.c
  119. fetch-pack.h
  120. fmt-merge-msg.h
  121. fsck.c
  122. fsck.h
  123. generate-cmdlist.sh
  124. gettext.c
  125. gettext.h
  126. git-add--interactive.perl
  127. git-archimport.perl
  128. git-bisect.sh
  129. git-compat-util.h
  130. git-cvsexportcommit.perl
  131. git-cvsimport.perl
  132. git-cvsserver.perl
  133. git-difftool--helper.sh
  134. git-filter-branch.sh
  135. git-instaweb.sh
  136. git-merge-octopus.sh
  137. git-merge-one-file.sh
  138. git-merge-resolve.sh
  139. git-mergetool--lib.sh
  140. git-mergetool.sh
  141. git-p4.py
  142. git-parse-remote.sh
  143. git-quiltimport.sh
  144. git-rebase--am.sh
  145. git-rebase--interactive.sh
  146. git-rebase--merge.sh
  147. git-rebase.sh
  148. git-remote-testgit.sh
  149. git-request-pull.sh
  150. git-send-email.perl
  151. git-sh-i18n.sh
  152. git-sh-setup.sh
  153. git-stash.sh
  154. git-submodule.sh
  155. git-svn.perl
  156. GIT-VERSION-GEN
  157. git-web--browse.sh
  158. git.c
  159. git.rc
  160. gpg-interface.c
  161. gpg-interface.h
  162. graph.c
  163. graph.h
  164. grep.c
  165. grep.h
  166. hash.h
  167. hashmap.c
  168. hashmap.h
  169. help.c
  170. help.h
  171. hex.c
  172. http-backend.c
  173. http-fetch.c
  174. http-push.c
  175. http-walker.c
  176. http.c
  177. http.h
  178. ident.c
  179. imap-send.c
  180. INSTALL
  181. iterator.h
  182. khash.h
  183. kwset.c
  184. kwset.h
  185. levenshtein.c
  186. levenshtein.h
  187. LGPL-2.1
  188. line-log.c
  189. line-log.h
  190. line-range.c
  191. line-range.h
  192. list-objects.c
  193. list-objects.h
  194. list.h
  195. ll-merge.c
  196. ll-merge.h
  197. lockfile.c
  198. lockfile.h
  199. log-tree.c
  200. log-tree.h
  201. mailinfo.c
  202. mailinfo.h
  203. mailmap.c
  204. mailmap.h
  205. Makefile
  206. match-trees.c
  207. merge-blobs.c
  208. merge-blobs.h
  209. merge-recursive.c
  210. merge-recursive.h
  211. merge.c
  212. mergesort.c
  213. mergesort.h
  214. mru.c
  215. mru.h
  216. name-hash.c
  217. notes-cache.c
  218. notes-cache.h
  219. notes-merge.c
  220. notes-merge.h
  221. notes-utils.c
  222. notes-utils.h
  223. notes.c
  224. notes.h
  225. object.c
  226. object.h
  227. oidset.c
  228. oidset.h
  229. pack-bitmap-write.c
  230. pack-bitmap.c
  231. pack-bitmap.h
  232. pack-check.c
  233. pack-objects.c
  234. pack-objects.h
  235. pack-revindex.c
  236. pack-revindex.h
  237. pack-write.c
  238. pack.h
  239. pager.c
  240. parse-options-cb.c
  241. parse-options.c
  242. parse-options.h
  243. patch-delta.c
  244. patch-ids.c
  245. patch-ids.h
  246. path.c
  247. pathspec.c
  248. pathspec.h
  249. pkt-line.c
  250. pkt-line.h
  251. preload-index.c
  252. pretty.c
  253. prio-queue.c
  254. prio-queue.h
  255. progress.c
  256. progress.h
  257. prompt.c
  258. prompt.h
  259. quote.c
  260. quote.h
  261. reachable.c
  262. reachable.h
  263. read-cache.c
  264. README.md
  265. ref-filter.c
  266. ref-filter.h
  267. reflog-walk.c
  268. reflog-walk.h
  269. refs.c
  270. refs.h
  271. remote-curl.c
  272. remote-testsvn.c
  273. remote.c
  274. remote.h
  275. replace_object.c
  276. rerere.c
  277. rerere.h
  278. resolve-undo.c
  279. resolve-undo.h
  280. revision.c
  281. revision.h
  282. run-command.c
  283. run-command.h
  284. send-pack.c
  285. send-pack.h
  286. sequencer.c
  287. sequencer.h
  288. server-info.c
  289. setup.c
  290. sh-i18n--envsubst.c
  291. sha1-array.c
  292. sha1-array.h
  293. sha1-lookup.c
  294. sha1-lookup.h
  295. sha1_file.c
  296. sha1_name.c
  297. sha1dc_git.c
  298. sha1dc_git.h
  299. shallow.c
  300. shell.c
  301. shortlog.h
  302. show-index.c
  303. sideband.c
  304. sideband.h
  305. sigchain.c
  306. sigchain.h
  307. split-index.c
  308. split-index.h
  309. strbuf.c
  310. strbuf.h
  311. streaming.c
  312. streaming.h
  313. string-list.c
  314. string-list.h
  315. sub-process.c
  316. sub-process.h
  317. submodule-config.c
  318. submodule-config.h
  319. submodule.c
  320. submodule.h
  321. symlinks.c
  322. tag.c
  323. tag.h
  324. tar.h
  325. tempfile.c
  326. tempfile.h
  327. thread-utils.c
  328. thread-utils.h
  329. tmp-objdir.c
  330. tmp-objdir.h
  331. trace.c
  332. trace.h
  333. trailer.c
  334. trailer.h
  335. transport-helper.c
  336. transport.c
  337. transport.h
  338. tree-diff.c
  339. tree-walk.c
  340. tree-walk.h
  341. tree.c
  342. tree.h
  343. unicode_width.h
  344. unimplemented.sh
  345. unix-socket.c
  346. unix-socket.h
  347. unpack-trees.c
  348. unpack-trees.h
  349. upload-pack.c
  350. url.c
  351. url.h
  352. urlmatch.c
  353. urlmatch.h
  354. usage.c
  355. userdiff.c
  356. userdiff.h
  357. utf8.c
  358. utf8.h
  359. varint.c
  360. varint.h
  361. version.c
  362. version.h
  363. versioncmp.c
  364. walker.c
  365. walker.h
  366. wildmatch.c
  367. wildmatch.h
  368. worktree.c
  369. worktree.h
  370. wrap-for-bin.sh
  371. wrapper.c
  372. write_or_die.c
  373. ws.c
  374. wt-status.c
  375. wt-status.h
  376. xdiff-interface.c
  377. xdiff-interface.h
  378. zlib.c
README.md

Git - fast, scalable, distributed revision control system

Git is a fast, scalable, distributed revision control system with an unusually rich command set that provides both high-level operations and full access to internals.

Git is an Open Source project covered by the GNU General Public License version 2 (some parts of it are under different licenses, compatible with the GPLv2). It was originally written by Linus Torvalds with help of a group of hackers around the net.

Please read the file INSTALL for installation instructions.

Many Git online resources are accessible from https://git-scm.com/ including full documentation and Git related tools.

See Documentation/gittutorial.txt to get started, then see Documentation/giteveryday.txt for a useful minimum set of commands, and Documentation/git-.txt for documentation of each command. If git has been correctly installed, then the tutorial can also be read with man gittutorial or git help tutorial, and the documentation of each command with man git-<commandname> or git help <commandname>.

CVS users may also want to read Documentation/gitcvs-migration.txt (man gitcvs-migration or git help cvs-migration if git is installed).

The user discussion and development of Git take place on the Git mailing list -- everyone is welcome to post bug reports, feature requests, comments and patches to git@vger.kernel.org (read Documentation/SubmittingPatches for instructions on patch submission). To subscribe to the list, send an email with just “subscribe git” in the body to majordomo@vger.kernel.org. The mailing list archives are available at https://public-inbox.org/git/, http://marc.info/?l=git and other archival sites.

The maintainer frequently sends the “What's cooking” reports that list the current status of various development topics to the mailing list. The discussion following them give a good reference for project status, development direction and remaining tasks.

The name “git” was given by Linus Torvalds when he wrote the very first version. He described the tool as “the stupid content tracker” and the name as (depending on your mood):

  • random three-letter combination that is pronounceable, and not actually used by any common UNIX command. The fact that it is a mispronunciation of “get” may or may not be relevant.
  • stupid. contemptible and despicable. simple. Take your pick from the dictionary of slang.
  • “global information tracker”: you're in a good mood, and it actually works for you. Angels sing, and a light suddenly fills the room.
  • “goddamn idiotic truckload of sh*t”: when it breaks