git notes merge: --commit should fail if underlying notes ref has moved

When manually resolving a notes merge, if the merging ref has moved since
the merge started, we should fail to complete the merge, and alert the user
to what's going on.

This situation may arise if you start a 'git notes merge' which results in
conflicts, and you then update the current notes ref (using for example
'git notes add/copy/amend/edit/remove/prune', 'git update-ref', etc.),
before you get around to resolving the notes conflicts and calling
'git notes merge --commit'.

We detect this situation by comparing the first parent of the partial merge
commit (which was created when the merge started) to the current value of the
merging notes ref (pointed to by the .git/NOTES_MERGE_REF symref).

If we don't fail in this situation, the notes merge commit would overwrite
the updated notes ref, thus losing the changes that happened in the meantime.

The patch includes a testcase verifying that we fail correctly in this
situation.

Signed-off-by: Johan Herland <johan@herland.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 files changed
tree: c0596682504898624057f102066fe4beddea3e5f
  1. block-sha1/
  2. builtin/
  3. compat/
  4. contrib/
  5. Documentation/
  6. git-gui/
  7. git_remote_helpers/
  8. gitk-git/
  9. gitweb/
  10. perl/
  11. ppc/
  12. t/
  13. templates/
  14. xdiff/
  15. .gitattributes
  16. .gitignore
  17. .mailmap
  18. abspath.c
  19. aclocal.m4
  20. advice.c
  21. advice.h
  22. alias.c
  23. alloc.c
  24. archive-tar.c
  25. archive-zip.c
  26. archive.c
  27. archive.h
  28. attr.c
  29. attr.h
  30. base85.c
  31. bisect.c
  32. bisect.h
  33. blob.c
  34. blob.h
  35. branch.c
  36. branch.h
  37. builtin.h
  38. bundle.c
  39. bundle.h
  40. cache-tree.c
  41. cache-tree.h
  42. cache.h
  43. check-builtins.sh
  44. check-racy.c
  45. check_bindir
  46. color.c
  47. color.h
  48. combine-diff.c
  49. command-list.txt
  50. commit.c
  51. commit.h
  52. config.c
  53. config.mak.in
  54. configure.ac
  55. connect.c
  56. convert.c
  57. copy.c
  58. COPYING
  59. csum-file.c
  60. csum-file.h
  61. ctype.c
  62. daemon.c
  63. date.c
  64. decorate.c
  65. decorate.h
  66. delta.h
  67. diff-delta.c
  68. diff-lib.c
  69. diff-no-index.c
  70. diff.c
  71. diff.h
  72. diffcore-break.c
  73. diffcore-delta.c
  74. diffcore-order.c
  75. diffcore-pickaxe.c
  76. diffcore-rename.c
  77. diffcore.h
  78. dir.c
  79. dir.h
  80. editor.c
  81. entry.c
  82. environment.c
  83. exec_cmd.c
  84. exec_cmd.h
  85. fast-import.c
  86. fetch-pack.h
  87. fixup-builtins
  88. fsck.c
  89. fsck.h
  90. generate-cmdlist.sh
  91. git-add--interactive.perl
  92. git-am.sh
  93. git-archimport.perl
  94. git-bisect.sh
  95. git-compat-util.h
  96. git-cvsexportcommit.perl
  97. git-cvsimport.perl
  98. git-cvsserver.perl
  99. git-difftool--helper.sh
  100. git-difftool.perl
  101. git-filter-branch.sh
  102. git-instaweb.sh
  103. git-lost-found.sh
  104. git-merge-octopus.sh
  105. git-merge-one-file.sh
  106. git-merge-resolve.sh
  107. git-mergetool--lib.sh
  108. git-mergetool.sh
  109. git-parse-remote.sh
  110. git-pull.sh
  111. git-quiltimport.sh
  112. git-rebase--interactive.sh
  113. git-rebase.sh
  114. git-relink.perl
  115. git-remote-testgit.py
  116. git-repack.sh
  117. git-request-pull.sh
  118. git-send-email.perl
  119. git-sh-setup.sh
  120. git-stash.sh
  121. git-submodule.sh
  122. git-svn.perl
  123. GIT-VERSION-GEN
  124. git-web--browse.sh
  125. git.c
  126. git.spec.in
  127. graph.c
  128. graph.h
  129. grep.c
  130. grep.h
  131. hash.c
  132. hash.h
  133. help.c
  134. help.h
  135. hex.c
  136. http-backend.c
  137. http-fetch.c
  138. http-push.c
  139. http-walker.c
  140. http.c
  141. http.h
  142. ident.c
  143. imap-send.c
  144. INSTALL
  145. levenshtein.c
  146. levenshtein.h
  147. list-objects.c
  148. list-objects.h
  149. ll-merge.c
  150. ll-merge.h
  151. lockfile.c
  152. log-tree.c
  153. log-tree.h
  154. mailmap.c
  155. mailmap.h
  156. Makefile
  157. match-trees.c
  158. merge-file.c
  159. merge-recursive.c
  160. merge-recursive.h
  161. name-hash.c
  162. notes-cache.c
  163. notes-cache.h
  164. notes-merge.c
  165. notes-merge.h
  166. notes.c
  167. notes.h
  168. object.c
  169. object.h
  170. pack-check.c
  171. pack-refs.c
  172. pack-refs.h
  173. pack-revindex.c
  174. pack-revindex.h
  175. pack-write.c
  176. pack.h
  177. pager.c
  178. parse-options.c
  179. parse-options.h
  180. patch-delta.c
  181. patch-ids.c
  182. patch-ids.h
  183. path.c
  184. pkt-line.c
  185. pkt-line.h
  186. preload-index.c
  187. pretty.c
  188. progress.c
  189. progress.h
  190. quote.c
  191. quote.h
  192. reachable.c
  193. reachable.h
  194. read-cache.c
  195. README
  196. reflog-walk.c
  197. reflog-walk.h
  198. refs.c
  199. refs.h
  200. remote-curl.c
  201. remote.c
  202. remote.h
  203. replace_object.c
  204. rerere.c
  205. rerere.h
  206. resolve-undo.c
  207. resolve-undo.h
  208. revision.c
  209. revision.h
  210. run-command.c
  211. run-command.h
  212. send-pack.h
  213. server-info.c
  214. setup.c
  215. sha1-lookup.c
  216. sha1-lookup.h
  217. sha1_file.c
  218. sha1_name.c
  219. shallow.c
  220. shell.c
  221. shortlog.h
  222. show-index.c
  223. sideband.c
  224. sideband.h
  225. sigchain.c
  226. sigchain.h
  227. strbuf.c
  228. strbuf.h
  229. string-list.c
  230. string-list.h
  231. submodule.c
  232. submodule.h
  233. symlinks.c
  234. tag.c
  235. tag.h
  236. tar.h
  237. test-chmtime.c
  238. test-ctype.c
  239. test-date.c
  240. test-delta.c
  241. test-dump-cache-tree.c
  242. test-genrandom.c
  243. test-index-version.c
  244. test-match-trees.c
  245. test-parse-options.c
  246. test-path-utils.c
  247. test-run-command.c
  248. test-sha1.c
  249. test-sha1.sh
  250. test-sigchain.c
  251. thread-utils.c
  252. thread-utils.h
  253. trace.c
  254. transport-helper.c
  255. transport.c
  256. transport.h
  257. tree-diff.c
  258. tree-walk.c
  259. tree-walk.h
  260. tree.c
  261. tree.h
  262. unimplemented.sh
  263. unpack-trees.c
  264. unpack-trees.h
  265. upload-pack.c
  266. url.c
  267. url.h
  268. usage.c
  269. userdiff.c
  270. userdiff.h
  271. utf8.c
  272. utf8.h
  273. walker.c
  274. walker.h
  275. wrap-for-bin.sh
  276. wrapper.c
  277. write_or_die.c
  278. ws.c
  279. wt-status.c
  280. wt-status.h
  281. xdiff-interface.c
  282. xdiff-interface.h