describe: force long format for a name based on a mislocated tag

An annotated tag has two names: where it sits in the refs/tags
hierarchy and the tagname recorded in the "tag" field in the object
itself.  They usually should match.

Since 212945d4 ("Teach git-describe to verify annotated tag names
before output", 2008-02-28), a commit described using an annotated
tag bases its name on the tagname from the object.  While this was a
deliberate design decision to make it easier to converse about tags
with others, even if the tags happen to be fetched to a different
name than it was given by its creator, it had one downside.

The output from "git describe", at least in the modern Git, should
be usable as an object name to name the exact commit given to the
"git describe" command.  Using the tagname, when two names differ,
breaks this property, when describing a commit that is directly
pointed at by such a tag.  An annotated tag Bob made as "v1.0" may
sit at "refs/tags/v1.0-bob" in the ref hierarchy, and output from
"git describe v1.0-bob^0" would say "v1.0", but there may not be
any tag at "refs/tags/v1.0" locally or there may be another tag that
points at a different object.

Note that this won't be a problem if a commit being described is not
directly pointed at by such a mislocated tag.  In the example in the
previous paragraph, describing a commit whose parent is v1.0-bob
would result in "v1.0" (i.e. the tagname taken from the tag object)
followed by "-1-gXXXXX" where XXXXX is the abbreviated object name,
and a string that ends with "-g" followed by a hexadecimal string is
an object name for the object whose name begins with hexadecimal
string (as long as it is unique), so it does not matter if the
leading part is "v1.0" or "v1.0-bob".

Show the name in the long format, i.e. with "-0-gXXXXX" suffix, when
the name we give is based on a mislocated annotated tag to ensure
that the output can be used as the object name for the object
originally given to the command to fix the issue.

While at it, remove an overly cautious dead code to protect against
an annotated tag object without the tagname.  Such a tag is filtered
out much earlier in the codeflow, and will not reach this part of
the code.

Helped-by: Matheus Tavares <matheus.bernardino@usp.br>
Helped-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 files changed
tree: 7262fdc26d7f0416bffeafe8cfa97786b3179037
  1. .clang-format
  2. .editorconfig
  3. .gitattributes
  4. .github/
  5. .gitignore
  6. .gitmodules
  7. .mailmap
  8. .travis.yml
  9. .tsan-suppressions
  10. CODE_OF_CONDUCT.md
  11. COPYING
  12. Documentation/
  13. GIT-VERSION-GEN
  14. INSTALL
  15. LGPL-2.1
  16. Makefile
  17. README.md
  18. abspath.c
  19. aclocal.m4
  20. advice.c
  21. advice.h
  22. alias.c
  23. alias.h
  24. alloc.c
  25. alloc.h
  26. apply.c
  27. apply.h
  28. archive-tar.c
  29. archive-zip.c
  30. archive.c
  31. archive.h
  32. argv-array.c
  33. argv-array.h
  34. attr.c
  35. attr.h
  36. azure-pipelines.yml
  37. banned.h
  38. base85.c
  39. bisect.c
  40. bisect.h
  41. blame.c
  42. blame.h
  43. blob.c
  44. blob.h
  45. block-sha1/
  46. branch.c
  47. branch.h
  48. builtin.h
  49. builtin/
  50. bulk-checkin.c
  51. bulk-checkin.h
  52. bundle.c
  53. bundle.h
  54. cache-tree.c
  55. cache-tree.h
  56. cache.h
  57. chdir-notify.c
  58. chdir-notify.h
  59. check-builtins.sh
  60. check_bindir
  61. checkout.c
  62. checkout.h
  63. ci/
  64. color.c
  65. color.h
  66. column.c
  67. column.h
  68. combine-diff.c
  69. command-list.txt
  70. commit-graph.c
  71. commit-graph.h
  72. commit-reach.c
  73. commit-reach.h
  74. commit-slab-decl.h
  75. commit-slab-impl.h
  76. commit-slab.h
  77. commit.c
  78. commit.h
  79. common-main.c
  80. compat/
  81. config.c
  82. config.h
  83. config.mak.dev
  84. config.mak.in
  85. config.mak.uname
  86. configure.ac
  87. connect.c
  88. connect.h
  89. connected.c
  90. connected.h
  91. contrib/
  92. convert.c
  93. convert.h
  94. copy.c
  95. credential-cache--daemon.c
  96. credential-cache.c
  97. credential-store.c
  98. credential.c
  99. credential.h
  100. csum-file.c
  101. csum-file.h
  102. ctype.c
  103. daemon.c
  104. date.c
  105. decorate.c
  106. decorate.h
  107. delta-islands.c
  108. delta-islands.h
  109. delta.h
  110. detect-compiler
  111. diff-delta.c
  112. diff-lib.c
  113. diff-no-index.c
  114. diff.c
  115. diff.h
  116. diffcore-break.c
  117. diffcore-delta.c
  118. diffcore-order.c
  119. diffcore-pickaxe.c
  120. diffcore-rename.c
  121. diffcore.h
  122. dir-iterator.c
  123. dir-iterator.h
  124. dir.c
  125. dir.h
  126. editor.c
  127. entry.c
  128. environment.c
  129. ewah/
  130. exec-cmd.c
  131. exec-cmd.h
  132. fast-import.c
  133. fetch-negotiator.c
  134. fetch-negotiator.h
  135. fetch-pack.c
  136. fetch-pack.h
  137. fmt-merge-msg.h
  138. fsck.c
  139. fsck.h
  140. fsmonitor.c
  141. fsmonitor.h
  142. fuzz-commit-graph.c
  143. fuzz-pack-headers.c
  144. fuzz-pack-idx.c
  145. generate-cmdlist.sh
  146. gettext.c
  147. gettext.h
  148. git-add--interactive.perl
  149. git-archimport.perl
  150. git-bisect.sh
  151. git-compat-util.h
  152. git-cvsexportcommit.perl
  153. git-cvsimport.perl
  154. git-cvsserver.perl
  155. git-difftool--helper.sh
  156. git-filter-branch.sh
  157. git-gui/
  158. git-instaweb.sh
  159. git-legacy-stash.sh
  160. git-merge-octopus.sh
  161. git-merge-one-file.sh
  162. git-merge-resolve.sh
  163. git-mergetool--lib.sh
  164. git-mergetool.sh
  165. git-p4.py
  166. git-parse-remote.sh
  167. git-quiltimport.sh
  168. git-rebase--preserve-merges.sh
  169. git-request-pull.sh
  170. git-send-email.perl
  171. git-sh-i18n.sh
  172. git-sh-setup.sh
  173. git-submodule.sh
  174. git-svn.perl
  175. git-web--browse.sh
  176. git.c
  177. git.rc
  178. gitk-git/
  179. gitweb/
  180. gpg-interface.c
  181. gpg-interface.h
  182. graph.c
  183. graph.h
  184. grep.c
  185. grep.h
  186. hash.h
  187. hashmap.c
  188. hashmap.h
  189. help.c
  190. help.h
  191. hex.c
  192. http-backend.c
  193. http-fetch.c
  194. http-push.c
  195. http-walker.c
  196. http.c
  197. http.h
  198. ident.c
  199. imap-send.c
  200. interdiff.c
  201. interdiff.h
  202. iterator.h
  203. json-writer.c
  204. json-writer.h
  205. khash.h
  206. kwset.c
  207. kwset.h
  208. levenshtein.c
  209. levenshtein.h
  210. line-log.c
  211. line-log.h
  212. line-range.c
  213. line-range.h
  214. linear-assignment.c
  215. linear-assignment.h
  216. list-objects-filter-options.c
  217. list-objects-filter-options.h
  218. list-objects-filter.c
  219. list-objects-filter.h
  220. list-objects.c
  221. list-objects.h
  222. list.h
  223. ll-merge.c
  224. ll-merge.h
  225. lockfile.c
  226. lockfile.h
  227. log-tree.c
  228. log-tree.h
  229. ls-refs.c
  230. ls-refs.h
  231. mailinfo.c
  232. mailinfo.h
  233. mailmap.c
  234. mailmap.h
  235. match-trees.c
  236. mem-pool.c
  237. mem-pool.h
  238. merge-blobs.c
  239. merge-blobs.h
  240. merge-recursive.c
  241. merge-recursive.h
  242. merge.c
  243. mergesort.c
  244. mergesort.h
  245. mergetools/
  246. midx.c
  247. midx.h
  248. name-hash.c
  249. negotiator/
  250. notes-cache.c
  251. notes-cache.h
  252. notes-merge.c
  253. notes-merge.h
  254. notes-utils.c
  255. notes-utils.h
  256. notes.c
  257. notes.h
  258. object-store.h
  259. object.c
  260. object.h
  261. oidmap.c
  262. oidmap.h
  263. oidset.c
  264. oidset.h
  265. pack-bitmap-write.c
  266. pack-bitmap.c
  267. pack-bitmap.h
  268. pack-check.c
  269. pack-objects.c
  270. pack-objects.h
  271. pack-revindex.c
  272. pack-revindex.h
  273. pack-write.c
  274. pack.h
  275. packfile.c
  276. packfile.h
  277. pager.c
  278. parse-options-cb.c
  279. parse-options.c
  280. parse-options.h
  281. patch-delta.c
  282. patch-ids.c
  283. patch-ids.h
  284. path.c
  285. path.h
  286. pathspec.c
  287. pathspec.h
  288. perl/
  289. pkt-line.c
  290. pkt-line.h
  291. po/
  292. ppc/
  293. preload-index.c
  294. pretty.c
  295. pretty.h
  296. prio-queue.c
  297. prio-queue.h
  298. progress.c
  299. progress.h
  300. promisor-remote.c
  301. promisor-remote.h
  302. prompt.c
  303. prompt.h
  304. protocol.c
  305. protocol.h
  306. quote.c
  307. quote.h
  308. range-diff.c
  309. range-diff.h
  310. reachable.c
  311. reachable.h
  312. read-cache.c
  313. rebase-interactive.c
  314. rebase-interactive.h
  315. ref-filter.c
  316. ref-filter.h
  317. reflog-walk.c
  318. reflog-walk.h
  319. refs.c
  320. refs.h
  321. refs/
  322. refspec.c
  323. refspec.h
  324. remote-curl.c
  325. remote-testsvn.c
  326. remote.c
  327. remote.h
  328. replace-object.c
  329. replace-object.h
  330. repo-settings.c
  331. repository.c
  332. repository.h
  333. rerere.c
  334. rerere.h
  335. resolve-undo.c
  336. resolve-undo.h
  337. revision.c
  338. revision.h
  339. run-command.c
  340. run-command.h
  341. send-pack.c
  342. send-pack.h
  343. sequencer.c
  344. sequencer.h
  345. serve.c
  346. serve.h
  347. server-info.c
  348. setup.c
  349. sh-i18n--envsubst.c
  350. sha1-array.c
  351. sha1-array.h
  352. sha1-file.c
  353. sha1-lookup.c
  354. sha1-lookup.h
  355. sha1-name.c
  356. sha1dc/
  357. sha1dc_git.c
  358. sha1dc_git.h
  359. sha256/
  360. shallow.c
  361. shell.c
  362. shortlog.h
  363. sideband.c
  364. sideband.h
  365. sigchain.c
  366. sigchain.h
  367. split-index.c
  368. split-index.h
  369. stable-qsort.c
  370. strbuf.c
  371. strbuf.h
  372. streaming.c
  373. streaming.h
  374. string-list.c
  375. string-list.h
  376. sub-process.c
  377. sub-process.h
  378. submodule-config.c
  379. submodule-config.h
  380. submodule.c
  381. submodule.h
  382. symlinks.c
  383. t/
  384. tag.c
  385. tag.h
  386. tar.h
  387. tempfile.c
  388. tempfile.h
  389. templates/
  390. thread-utils.c
  391. thread-utils.h
  392. tmp-objdir.c
  393. tmp-objdir.h
  394. trace.c
  395. trace.h
  396. trace2.c
  397. trace2.h
  398. trace2/
  399. trailer.c
  400. trailer.h
  401. transport-helper.c
  402. transport-internal.h
  403. transport.c
  404. transport.h
  405. tree-diff.c
  406. tree-walk.c
  407. tree-walk.h
  408. tree.c
  409. tree.h
  410. unicode-width.h
  411. unimplemented.sh
  412. unix-socket.c
  413. unix-socket.h
  414. unpack-trees.c
  415. unpack-trees.h
  416. upload-pack.c
  417. upload-pack.h
  418. url.c
  419. url.h
  420. urlmatch.c
  421. urlmatch.h
  422. usage.c
  423. userdiff.c
  424. userdiff.h
  425. utf8.c
  426. utf8.h
  427. varint.c
  428. varint.h
  429. vcs-svn/
  430. version.c
  431. version.h
  432. versioncmp.c
  433. walker.c
  434. walker.h
  435. wildmatch.c
  436. wildmatch.h
  437. worktree.c
  438. worktree.h
  439. wrap-for-bin.sh
  440. wrapper.c
  441. write-or-die.c
  442. ws.c
  443. wt-status.c
  444. wt-status.h
  445. xdiff-interface.c
  446. xdiff-interface.h
  447. xdiff/
  448. zlib.c
README.md

Build Status

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-<commandname>.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.

Issues which are security relevant should be disclosed privately to the Git Security mailing list git-security@googlegroups.com.

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