Skip to content

Commit 72af62b

Browse files
committed
mdist: detect pathological git repo cases and show a slightly better error
When `meson dist` fails with the error: ``` Dist currently only works with Git or Mercurial repos ``` It is sometimes inaccurate, since a git repo may exist but be nonfunctional. Offer some better guidance in that case. Fixes: mesonbuild#10866 (cherry picked from commit 81c5088)
1 parent 54e35c1 commit 72af62b

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

mesonbuild/mdist.py

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from glob import glob
2323
from pathlib import Path
2424
from mesonbuild.environment import Environment, detect_ninja
25-
from mesonbuild.mesonlib import (MesonException, RealPathAction, get_meson_command, quiet_git,
25+
from mesonbuild.mesonlib import (GIT, MesonException, RealPathAction, get_meson_command, quiet_git,
2626
windows_proof_rmtree, setup_vsenv, OptionKey)
2727
from mesonbuild.msetup import add_arguments as msetup_argparse
2828
from mesonbuild.wrap import wrap
@@ -79,7 +79,36 @@ def is_git(src_root: str) -> bool:
7979
Checks if meson.build file at the root source directory is tracked by git.
8080
It could be a subproject part of the parent project git repository.
8181
'''
82-
return quiet_git(['ls-files', '--error-unmatch', 'meson.build'], src_root)[0]
82+
if quiet_git(['ls-files', '--error-unmatch', 'meson.build'], src_root)[0]:
83+
return True
84+
85+
if os.path.exists(os.path.join(src_root, '.git')):
86+
msg = 'Source tree looks like it may be a git repo, '
87+
if not GIT:
88+
msg += 'but git is not installed!'
89+
if 'GITLAB_CI' in os.environ:
90+
msg += ' This is a gitlab bug.'
91+
else:
92+
msg += 'but git returned a failure. '
93+
p, oe = quiet_git(['status'], src_root)
94+
if 'dubious ownership' in oe:
95+
# For a few years now, git has absolved itself of the responsibility to implement
96+
# robust, safe software. Instead of detecting the signs of a problematic scenario,
97+
# they have chosen to consider many legitimate and reasonable use cases as "dangerous",
98+
# and implemented the number one threat to security worldwide: alert fatigue. Having
99+
# done so, they then washed their hands of the matter and permanently tabled the
100+
# notion of adding fine-grained detection. This is not just useless, it is *worse*
101+
# than useless.
102+
#
103+
# In our case, the error is triply meaningless since we are already executing build
104+
# system commands from the same directory. Either way, reject the notion that git is
105+
# well designed or that its error messaging is a valid approach to the problem space.
106+
msg += 'This is a bug in git itself, please set `git config --global safe.directory "*"`'
107+
else:
108+
msg += 'meson.build may not have been committed to git?'
109+
mlog.warning(msg)
110+
return False
111+
83112

84113
def is_hg(src_root: str) -> bool:
85114
return os.path.isdir(os.path.join(src_root, '.hg'))

0 commit comments

Comments
 (0)