push: Provide situational hints for non-fast-forward errors

Pushing a non-fast-forward update to a remote repository will result in
an error, but the hint text doesn't provide the correct resolution in
every case. Give better resolution advice in three push scenarios:

1) If you push your current branch and it triggers a non-fast-forward
error, you should merge remote changes with 'git pull' before pushing
again.

2) If you push to a shared repository others push to, and your local
tracking branches are not kept up to date, the 'matching refs' default
will generate non-fast-forward errors on outdated branches. If this is
your workflow, the 'matching refs' default is not for you. Consider
setting the 'push.default' configuration variable to 'current' or
'upstream' to ensure only your current branch is pushed.

3) If you explicitly specify a ref that is not your current branch or
push matching branches with ':', you will generate a non-fast-forward
error if any pushed branch tip is out of date. You should checkout the
offending branch and merge remote changes before pushing again.

Teach transport.c to recognize these scenarios and configure push.c
to hint for them. If 'git push's default behavior changes or we
discover more scenarios, extension is easy. Standardize on the
advice API and add three new advice variables, 'pushNonFFCurrent',
'pushNonFFDefault', and 'pushNonFFMatching'. Setting any of these
to 'false' will disable their affiliated advice. Setting
'pushNonFastForward' to false will disable all three, thus preserving the
config option for users who already set it, but guaranteeing new
users won't disable push advice accidentally.

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