Skip to content

Commit d47fb33

Browse files
Calculate a sensible version for the current commit.
1 parent c8bdbf6 commit d47fb33

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

version.mk

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
1-
BRANCH_NAME = $(shell git name-rev --name-only HEAD)
1+
BRANCH_NAME = $(shell git rev-parse --abbrev-ref HEAD)
2+
3+
ifeq ($(BRANCH_NAME),HEAD)
4+
NAME = $(shell git name-rev --name-only HEAD)
5+
NAME_PARTS = $(subst ~, ,$(subst ^, ,$(NAME)))
6+
ifeq ($(words $(NAME_PARTS)),1)
7+
TAG = 1
8+
else
9+
TAG = 0
10+
VERSION_BRANCH = $(shell git rev-parse --short HEAD)
11+
endif
12+
else
13+
TAG = 0
214
UPSTREAM = $(shell git config --get branch.$(BRANCH_NAME).merge)
315
ifeq ($(UPSTREAM),)
416
BRANCH ?= $(BRANCH_NAME)
517
else
618
BRANCH ?= $(shell git rev-parse --symbolic-full-name --abbrev-ref @{upstream})
719
endif
8-
VERSION_BRANCH = $(shell echo "$(BRANCH_NAME)" | tr A-Z-/ a-z.)
20+
VERSION_BRANCH = $(shell basename "$(BRANCH_NAME)" | tr A-Z-_ a-z.)
21+
endif # for ifeq ($(BRANCH_NAME),HEAD)
922

1023
DESCRIBE = $(shell git describe --tags --long --always $(BRANCH))
1124
DESC_LIST = $(subst -, ,$(DESCRIBE))
@@ -18,13 +31,12 @@ SHA = $(word 1,$(DESC_LIST))
1831
endif
1932

2033
REV_SUFFIX = $(or\
34+
$(if $(findstring 1,$(TAG)),""),\
2135
$(if $(findstring master,$(BRANCH)),""),\
2236
$(if $(findstring develop,$(BRANCH)),.dev$(COUNT)),\
2337
$(if $(findstring release/,$(BRANCH)),rc$(COUNT)),\
2438
$(if $(findstring hotfix/,$(BRANCH)),rc$(COUNT)),\
25-
$(if $(findstring feature/,$(BRANCH)),.dev$(COUNT)+$(VERSION_BRANCH)),\
26-
$(if $(findstring bugfix/,$(BRANCH)),.dev$(COUNT)+$(VERSION_BRANCH)),\
27-
.dev0+badbranch\
39+
.dev$(COUNT)+$(VERSION_BRANCH)\
2840
)
2941
BASE_VERSION = $(shell cat VERSION)
3042
VERSION = $(BASE_VERSION)$(REV_SUFFIX)

0 commit comments

Comments
 (0)