luci.mk: rework logic to determine current branch
authorJo-Philipp Wich <jo@mein.io>
Sat, 10 Sep 2022 12:54:25 +0000 (14:54 +0200)
committerJo-Philipp Wich <jo@mein.io>
Mon, 24 Oct 2022 23:03:36 +0000 (01:03 +0200)
In case `git branch --remote` yields no result, fall back to `git branch`
without `--remote` since it is possible that the local branch has not
been pushed yet.

Also simplify extraction of the branch name by not passing `--verbose`
and utilizing variable substitutions instead of sed expressions.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
luci.mk

diff --git a/luci.mk b/luci.mk
index bb4296aaed7372c0e0f73e3cb345d96ba6a05779..7aaca0c24d45b7b303263342f04813cf95fab48a 100644 (file)
--- a/luci.mk
+++ b/luci.mk
@@ -113,10 +113,11 @@ PKG_SRC_VERSION?=$(if $(DUMP),x,$(strip $(call findrev,1)))
 PKG_GITBRANCH?=$(if $(DUMP),x,$(strip $(shell \
        variant="LuCI"; \
        if git log -1 >/dev/null 2>/dev/null; then \
-               branch="$$(git branch --remote --verbose --no-abbrev --contains 2>/dev/null | \
-                       sed -rne 's|^[^/]+/([^ ]+) [a-f0-9]{40} .+$$|\1|p' | head -n1)"; \
+               branch=$$(git branch --remote --no-abbrev --contains 2>/dev/null | tail -n1); \
+               branch=$${branch:-$$(git branch --no-abbrev --contains 2>/dev/null)}; \
+               branch=$${branch#? }; branch=$${branch#*/}; \
                if [ "$$branch" != "master" ]; then \
-                       variant="LuCI $$branch branch"; \
+                       variant="LuCI $${branch:-unknown} branch"; \
                else \
                        variant="LuCI Master"; \
                fi; \