-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmisc.git.inc.mk
More file actions
84 lines (70 loc) · 5.12 KB
/
Copy pathmisc.git.inc.mk
File metadata and controls
84 lines (70 loc) · 5.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# sync with sh/git.inc.sh
GIT_DIR = $(shell $(GIT) rev-parse --path-format=absolute --git-dir 2>/dev/null)
GIT_DIR_REL = $(shell $(GIT) rev-parse --path-format=relative --git-dir 2>/dev/null)
GIT_COMMON_DIR = $(shell $(GIT) rev-parse --path-format=absolute --git-common-dir 2>/dev/null)
GIT_COMMON_DIR_REL = $(shell $(GIT) rev-parse --path-format=relative --git-common-dir 2>/dev/null)
GIT_BRANCH = $(shell $(GIT) rev-parse --abbrev-ref HEAD 2>/dev/null)
GIT_BRANCH_SHORT = $(notdir $(GIT_BRANCH))
GIT_BRANCH_DEFAULT = $(shell $(GIT) ls-remote --symref $(GIT_REMOTE_OR_ORIGIN) HEAD | $(HEAD) -n1 | $(CUT) -f1 | $(SED) "s|^ref: refs/heads/||") # editorconfig-checker-disable-line
ifdef SEMAPHORE_GIT_BRANCH
GIT_BRANCH = $(SEMAPHORE_GIT_BRANCH)
endif
ifdef TRAVIS_BRANCH
GIT_BRANCH = $(TRAVIS_BRANCH)
endif
GIT_DESCRIBE = $(shell $(GIT) describe --tags --first-parent --always --dirty 2>/dev/null)
GIT_DESCRIBE_MAJOR = $(word 1,$(subst ., ,$(GIT_DESCRIBE)))
GIT_DESCRIBE_MAJOR_MINOR = $(word 1,$(subst ., ,$(GIT_DESCRIBE))).$(word 2,$(subst ., ,$(GIT_DESCRIBE)))
GIT_COMMIT_MSG = $(shell $(GIT) log -1 --format="%B" 2>/dev/null)
GIT_HASH = $(shell $(GIT) rev-parse HEAD 2>/dev/null)
GIT_HASH_SHORT = $(shell $(GIT) rev-parse --short HEAD 2>/dev/null)
GIT_TAGS = $(shell $(GIT) tag --points-at HEAD 2>/dev/null)
GIT_TAG = $(shell $(GIT) tag --points-at HEAD | $(HEAD) -n1 2>/dev/null)
GIT_REMOTE = $(shell $(GIT) config branch.$(GIT_BRANCH).remote 2>/dev/null)
GIT_REMOTE_ORIGIN = origin
GIT_REMOTE_OR_ORIGIN = $(shell GIT_REMOTE=$(GIT_REMOTE); $(ECHO) $${GIT_REMOTE:-$(GIT_REMOTE_ORIGIN)})
GIT_ROOT = $(shell $(GIT) rev-parse --show-toplevel 2>/dev/null)
GIT_ROOT_REL = $(shell python3 -c "import os.path; print('%s' % os.path.relpath('$(GIT_ROOT)', '$(MAKE_PATH)'))")
$(foreach VAR,GIT_REMOTE GIT_REMOTE_OR_ORIGIN GIT_ROOT GIT_ROOT_REL,$(call make-lazy-once,$(VAR)))
# editorconfig-checker-disable max_line_length
# NOTE cannot use # editorconfig-checker-disable-line because it might add faux whitespace
GIT_REMOTE_URL = $(shell $(GIT) config remote.$(GIT_REMOTE).url 2>/dev/null)
GIT_REMOTE_SLUG = $(shell test -n $(GIT_REMOTE_URL); GIT_REMOTE_URL=$(GIT_REMOTE_URL); basename $$(dirname "$${GIT_REMOTE_URL//://}"))/$(shell basename "$(GIT_REMOTE_URL)" .git)
GIT_REMOTE_ORIGIN_URL ?= $(shell $(GIT) config remote.$(GIT_REMOTE_ORIGIN).url 2>/dev/null)
GIT_REMOTE_ORIGIN_SLUG ?= $(shell test -n $(GIT_REMOTE_ORIGIN_URL); GIT_REMOTE_ORIGIN_URL=$(GIT_REMOTE_ORIGIN_URL); basename $$(dirname "$${GIT_REMOTE_ORIGIN_URL//://}"))/$(shell basename "$(GIT_REMOTE_ORIGIN_URL)" .git)
GIT_REMOTE_OR_ORIGIN_URL = $(shell $(GIT) config remote.$(GIT_REMOTE_OR_ORIGIN).url 2>/dev/null)
GIT_REMOTE_OR_ORIGIN_SLUG = $(shell test -n $(GIT_REMOTE_OR_ORIGIN_URL); GIT_REMOTE_OR_ORIGIN_URL=$(GIT_REMOTE_OR_ORIGIN_URL); basename $$(dirname "$${GIT_REMOTE_OR_ORIGIN_URL//://}"))/$(shell basename "$(GIT_REMOTE_OR_ORIGIN_URL)" .git)
# editorconfig-checker-enable max_line_length
GIT_REPO_HAS_CHANGED_FILES = $(shell $(GIT) status --porcelain | $(GREP) -q -v -e "^$$" && \
$(ECHO) true || $(ECHO) false)
GIT_REPO_HAS_STAGED_FILES = $(shell $(GIT) status --porcelain | $(GREP) -q -e "^[^ U\?]" && \
$(ECHO) true || $(ECHO) false)
GIT_REPO_HAS_UNSTAGED_FILES = $(shell $(GIT) status --porcelain | $(GREP) -q -e "^ [^ ]" && \
$(ECHO) true || $(ECHO) false)
GIT_REPO_HAS_UNTRACKED_FILES = $(shell $(GIT) status --porcelain | $(GREP) -q -e "^?\?" && \
$(ECHO) true || $(ECHO) false)
GIT_REPO_HAS_CONFLICTS = $(shell $(GIT) status --porcelain | $(GREP) -q -e "^\(DD\|AU\|UD\|UA\|DU\|AA\|UU\)" && \
$(ECHO) true || $(ECHO) false)
GIT_CHECK_IGNORE = $(shell $(GIT) check-ignore $(MAKE_PATH) >/dev/null 2>&1 && $(ECHO) true || $(ECHO) false)
GIT_INSIDE_WORK_TREE = $(shell $(GIT) rev-parse --is-inside-work-tree >/dev/null 2>&1 && $(ECHO) true || $(ECHO) false)
GIT_TRACKED := false
ifeq (truefalse,$(GIT_INSIDE_WORK_TREE)$(GIT_CHECK_IGNORE))
GIT_TRACKED := true
endif
# editorconfig-checker-disable max_line_length
# NOTE cannot use # editorconfig-checker-disable-line because it might add faux whitespace
# Convert common git remote forms to git@host:org/repo.git.
git_url_to_ssh = $(if $(strip $(1)),$(call git_url_to_ssh/_from,$(strip $(1))),:)
git_url_to_ssh/_from = $(if $(findstring ://,$(1)),$(call git_url_to_ssh/_scheme,$(1)),$(call git_url_to_ssh/_scp,$(1)))
git_url_to_ssh/_scheme = $(call git_url_to_ssh/_build,$(call git_url_to_ssh/_host,$(call git_url_to_ssh/_scheme_rest,$(1))),$(call git_url_to_ssh/_path,$(call git_url_to_ssh/_scheme_rest,$(1))))
git_url_to_ssh/_scp = $(call git_url_to_ssh/_build,$(call git_url_to_ssh/_host,$(subst :,/,$(1))),$(call git_url_to_ssh/_path,$(subst :,/,$(1))))
git_url_to_ssh/_scheme_rest = $(patsubst https://%,%,$(patsubst http://%,%,$(patsubst ssh://%,%,$(patsubst git://%,%,$(1)))))
git_url_to_ssh/_host = $(lastword $(subst @, ,$(firstword $(subst /, ,$(1)))))
git_url_to_ssh/_path = $(patsubst %.git,%,$(patsubst %/,%,$(patsubst $(firstword $(subst /, ,$(1)))/%,%,$(1))))
git_url_to_ssh/_build = git@$(1):$(2).git
# editorconfig-checker-enable max_line_length
# ------------------------------------------------------------------------------
.PHONY: debug/git
debug/git: debug/env/git
debug/git:
: