branch: allow a no-op "branch -M <current-branch> HEAD"

Overwriting the current branch with a different commit is forbidden, as it
will make the status recorded in the index and the working tree out of
sync with respect to the HEAD. There however is no reason to forbid it if
the current branch is renamed to itself, which admittedly is something
only an insane user would do, but is handy for scripts.

Test script is by Conrad Irwin.

Reported-by: Soeren Sonnenburg <sonne@debian.org>
Reported-by: Josh Chia (谢任中)
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Conrad Irwin <conrad.irwin@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 files changed
tree: 04944df5313a8383faec47b1ad5d9b0426db2841
  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. bundle.c
  44. bundle.h
  45. cache-tree.c
  46. cache-tree.h
  47. cache.h
  48. check-builtins.sh
  49. check-racy.c
  50. check_bindir
  51. color.c
  52. color.h
  53. combine-diff.c
  54. command-list.txt
  55. commit.c
  56. commit.h
  57. config.c
  58. config.mak.in
  59. configure.ac
  60. connect.c
  61. connected.c
  62. connected.h
  63. convert.c
  64. convert.h
  65. copy.c
  66. COPYING
  67. csum-file.c
  68. csum-file.h
  69. ctype.c
  70. daemon.c
  71. date.c
  72. decorate.c
  73. decorate.h
  74. delta.h
  75. diff-delta.c
  76. diff-lib.c
  77. diff-no-index.c
  78. diff.c
  79. diff.h
  80. diffcore-break.c
  81. diffcore-delta.c
  82. diffcore-order.c
  83. diffcore-pickaxe.c
  84. diffcore-rename.c
  85. diffcore.h
  86. dir.c
  87. dir.h
  88. editor.c
  89. entry.c
  90. environment.c
  91. exec_cmd.c
  92. exec_cmd.h
  93. fast-import.c
  94. fetch-pack.h
  95. fixup-builtins
  96. fsck.c
  97. fsck.h
  98. generate-cmdlist.sh
  99. gettext.c
  100. gettext.h
  101. git-add--interactive.perl
  102. git-am.sh
  103. git-archimport.perl
  104. git-bisect.sh
  105. git-compat-util.h
  106. git-cvsexportcommit.perl
  107. git-cvsimport.perl
  108. git-cvsserver.perl
  109. git-difftool--helper.sh
  110. git-difftool.perl
  111. git-filter-branch.sh
  112. git-instaweb.sh
  113. git-lost-found.sh
  114. git-merge-octopus.sh
  115. git-merge-one-file.sh
  116. git-merge-resolve.sh
  117. git-mergetool--lib.sh
  118. git-mergetool.sh
  119. git-parse-remote.sh
  120. git-pull.sh
  121. git-quiltimport.sh
  122. git-rebase--am.sh
  123. git-rebase--interactive.sh
  124. git-rebase--merge.sh
  125. git-rebase.sh
  126. git-relink.perl
  127. git-remote-testgit.py
  128. git-repack.sh
  129. git-request-pull.sh
  130. git-send-email.perl
  131. git-sh-i18n.sh
  132. git-sh-setup.sh
  133. git-stash.sh
  134. git-submodule.sh
  135. git-svn.perl
  136. GIT-VERSION-GEN
  137. git-web--browse.sh
  138. git.c
  139. git.spec.in
  140. graph.c
  141. graph.h
  142. grep.c
  143. grep.h
  144. hash.c
  145. hash.h
  146. help.c
  147. help.h
  148. hex.c
  149. http-backend.c
  150. http-fetch.c
  151. http-push.c
  152. http-walker.c
  153. http.c
  154. http.h
  155. ident.c
  156. imap-send.c
  157. INSTALL
  158. kwset.c
  159. kwset.h
  160. levenshtein.c
  161. levenshtein.h
  162. LGPL-2.1
  163. list-objects.c
  164. list-objects.h
  165. ll-merge.c
  166. ll-merge.h
  167. lockfile.c
  168. log-tree.c
  169. log-tree.h
  170. mailmap.c
  171. mailmap.h
  172. Makefile
  173. match-trees.c
  174. merge-file.c
  175. merge-file.h
  176. merge-recursive.c
  177. merge-recursive.h
  178. name-hash.c
  179. notes-cache.c
  180. notes-cache.h
  181. notes-merge.c
  182. notes-merge.h
  183. notes.c
  184. notes.h
  185. object.c
  186. object.h
  187. pack-check.c
  188. pack-refs.c
  189. pack-refs.h
  190. pack-revindex.c
  191. pack-revindex.h
  192. pack-write.c
  193. pack.h
  194. pager.c
  195. parse-options-cb.c
  196. parse-options.c
  197. parse-options.h
  198. patch-delta.c
  199. patch-ids.c
  200. patch-ids.h
  201. path.c
  202. pkt-line.c
  203. pkt-line.h
  204. preload-index.c
  205. pretty.c
  206. progress.c
  207. progress.h
  208. quote.c
  209. quote.h
  210. reachable.c
  211. reachable.h
  212. read-cache.c
  213. README
  214. reflog-walk.c
  215. reflog-walk.h
  216. refs.c
  217. refs.h
  218. remote-curl.c
  219. remote.c
  220. remote.h
  221. replace_object.c
  222. rerere.c
  223. rerere.h
  224. resolve-undo.c
  225. resolve-undo.h
  226. revision.c
  227. revision.h
  228. run-command.c
  229. run-command.h
  230. send-pack.h
  231. sequencer.c
  232. sequencer.h
  233. server-info.c
  234. setup.c
  235. sh-i18n--envsubst.c
  236. sha1-array.c
  237. sha1-array.h
  238. sha1-lookup.c
  239. sha1-lookup.h
  240. sha1_file.c
  241. sha1_name.c
  242. shallow.c
  243. shell.c
  244. shortlog.h
  245. show-index.c
  246. sideband.c
  247. sideband.h
  248. sigchain.c
  249. sigchain.h
  250. strbuf.c
  251. strbuf.h
  252. streaming.c
  253. streaming.h
  254. string-list.c
  255. string-list.h
  256. submodule.c
  257. submodule.h
  258. symlinks.c
  259. tag.c
  260. tag.h
  261. tar.h
  262. test-chmtime.c
  263. test-ctype.c
  264. test-date.c
  265. test-delta.c
  266. test-dump-cache-tree.c
  267. test-genrandom.c
  268. test-index-version.c
  269. test-line-buffer.c
  270. test-match-trees.c
  271. test-mktemp.c
  272. test-obj-pool.c
  273. test-parse-options.c
  274. test-path-utils.c
  275. test-run-command.c
  276. test-sha1.c
  277. test-sha1.sh
  278. test-sigchain.c
  279. test-string-pool.c
  280. test-subprocess.c
  281. test-svn-fe.c
  282. test-treap.c
  283. thread-utils.c
  284. thread-utils.h
  285. trace.c
  286. transport-helper.c
  287. transport.c
  288. transport.h
  289. tree-diff.c
  290. tree-walk.c
  291. tree-walk.h
  292. tree.c
  293. tree.h
  294. unimplemented.sh
  295. unpack-trees.c
  296. unpack-trees.h
  297. upload-pack.c
  298. url.c
  299. url.h
  300. usage.c
  301. userdiff.c
  302. userdiff.h
  303. utf8.c
  304. utf8.h
  305. walker.c
  306. walker.h
  307. wrap-for-bin.sh
  308. wrapper.c
  309. write_or_die.c
  310. ws.c
  311. wt-status.c
  312. wt-status.h
  313. xdiff-interface.c
  314. xdiff-interface.h
  315. zlib.c