From b047071ec58b5367cbac179fc94e47a3d69f3ec8 Mon Sep 17 00:00:00 2001 From: Michael Prokop Date: Thu, 24 Jun 2021 19:16:51 +0200 Subject: [PATCH] Fix git version detection when executing in foreign git repository When the working directory is a foreign git repository (other than grml-debootstrap.git), and grml-debootstrap is invoked with the full path pointing towards grml-debootstrap.git, then we're relying on `git describe` output of the other (foreign) repository, which is failing and reporting an unknown version. Demonstration: | % cd "$(mktemp -d)" | % git init | Initialized empty Git repository in /tmp/tmp.2TQO7PZPQX/.git/ | % ~/src/grml/grml-debootstrap/grml-debootstrap --version | fatal: No names found, cannot describe anything. | * grml-debootstrap - version unknown | * Report bugs via https://github.com/grml/grml-debootstrap/ or https://grml.org/bugs/ ... and also: | % cd "$(mktemp -d)" | % git init | Initialized empty Git repository in /tmp/tmp.Y15j7wMMOn/.git/ | % echo foo > foo | % git add foo ; git commit -m 'foo' | [main (root-commit) 5d4357c] foo | 1 file changed, 1 insertion(+) | create mode 100644 foo | % git tag 0.42 | % ~/src/grml/grml-debootstrap/grml-debootstrap --version | fatal: No annotated tags can describe '5d4357c0b5bb504e610265904619287be2c6718d'. | However, there were unannotated tags: try --tags. | * grml-debootstrap - version unknown | * Report bugs via https://github.com/grml/grml-debootstrap/ or https://grml.org/bugs/ Thanks: Paul Menzel for the bugreport Closes: grml/grml-debootstrap#183 --- grml-debootstrap | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grml-debootstrap b/grml-debootstrap index 2d9aa1d..1f4fa00 100755 --- a/grml-debootstrap +++ b/grml-debootstrap @@ -41,7 +41,7 @@ fi # variables {{{ PN="$(basename "$0")" if [[ -d "$(dirname "$(command -v "$0")")"/.git ]]; then - VERSION="$(git describe | sed 's|^v||')" + VERSION="$(git --git-dir $(dirname "$(command -v "$0")")/.git describe | sed 's|^v||')" else VERSION="$(dpkg-query --show --showformat='${Version}' "$PN")" fi -- 2.1.4