035c856c2cbbad2b45252ec8c065c3a9e7eefa65

Author
Marc Cornellà <hello@mcornella.com>
Committer
Marc Cornellà <hello@mcornella.com>
Date

Message

fix: get branch name first in `omz version` and changelog

Diff

 1diff --git a/lib/cli.zsh b/lib/cli.zsh
 2index 0a85402df8c500eb184f3e2034d765acd7cdf2c3..ec59d1d44fb502c56da20adca40a28c5b3694289 100644
 3--- a/lib/cli.zsh
 4+++ b/lib/cli.zsh
 5@@ -791,12 +791,13 @@ function _omz::version {
 6 
 7     # Get the version name:
 8     # 1) try tag-like version
 9-    # 2) try name-rev
10-    # 3) try branch name
11+    # 2) try branch name
12+    # 3) try name-rev (tag~<rev> or branch~<rev>)
13     local version
14     version=$(command git describe --tags HEAD 2>/dev/null) \
15+    || version=$(command git symbolic-ref --quiet --short HEAD 2>/dev/null) \
16     || version=$(command git name-rev --no-undefined --name-only --exclude="remotes/*" HEAD 2>/dev/null) \
17-    || version=$(command git symbolic-ref --quiet --short HEAD 2>/dev/null)
18+    || version="<detached>"
19 
20     # Get short hash for the current HEAD
21     local commit=$(command git rev-parse --short HEAD 2>/dev/null)
22diff --git a/tools/changelog.sh b/tools/changelog.sh
23index 86774a7ea1bdccfab5f2b2c242c823f9fd09f122..49532a4a451c7d7af4b10cf39487e4c1d55ad578 100755
24--- a/tools/changelog.sh
25+++ b/tools/changelog.sh
26@@ -395,12 +395,12 @@ function main {
27 
28   # Get the first version name:
29   # 1) try tag-like version, or
30-  # 2) try name-rev, or
31-  # 3) try branch name, or
32+  # 2) try branch name, or
33+  # 3) try name-rev, or
34   # 4) try short hash
35   version=$(command git describe --tags $until 2>/dev/null) \
36-    || version=$(command git name-rev --no-undefined --name-only --exclude="remotes/*" $until 2>/dev/null) \
37     || version=$(command git symbolic-ref --quiet --short $until 2>/dev/null) \
38+    || version=$(command git name-rev --no-undefined --name-only --exclude="remotes/*" $until 2>/dev/null) \
39     || version=$(command git rev-parse --short $until 2>/dev/null)
40 
41   # Get commit list from $until commit until $since commit, or until root commit if $since is unset