Fix git version detection when executing in foreign git repository master
authorMichael Prokop <mika@grml.org>
Thu, 24 Jun 2021 17:16:51 +0000 (19:16 +0200)
committerMichael Prokop <mika@grml.org>
Thu, 24 Jun 2021 17:22:31 +0000 (19:22 +0200)
commitb047071ec58b5367cbac179fc94e47a3d69f3ec8
treeaaa8ed4c951e3c3d0ae3dff4a52e60619e8c8e3f
parent59e75958079096421a679c83e2526c973038ba83
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