Skip to content

Commit c9aa4af

Browse files
bgilberteli-schwartz
authored andcommitted
mdist: gracefully handle stale Git index
Running `touch` on a tracked file in Git, to update its timestamp, and then running `meson dist` would cause dist to fail: ERROR: Repository has uncommitted changes that will not be included in the dist tarball Use --allow-dirty to ignore the warning and proceed anyway Unlike `git status` and `git diff`, `git diff-index` doesn't refresh the index before comparing, so stat changes are assumed to imply content changes. Run `git update-index -q --refresh` first to refresh the index. Fixes: mesonbuild#12985
1 parent 2004b7c commit c9aa4af

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

mesonbuild/mdist.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ def git_root(self, dir_: str) -> Path:
140140

141141
def have_dirty_index(self) -> bool:
142142
'''Check whether there are uncommitted changes in git'''
143+
subprocess.check_call(['git', '-C', self.src_root, 'update-index', '-q', '--refresh'])
143144
ret = subprocess.call(['git', '-C', self.src_root, 'diff-index', '--quiet', 'HEAD'])
144145
return ret == 1
145146

unittests/allplatformstests.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1494,7 +1494,8 @@ def dist_impl(self, vcs_init, vcs_add_all=None, include_subprojects=True):
14941494
subproject('tarballsub', required : false)
14951495
subproject('samerepo', required : false)
14961496
'''))
1497-
with open(os.path.join(project_dir, 'distexe.c'), 'w', encoding='utf-8') as ofile:
1497+
distexe_c = os.path.join(project_dir, 'distexe.c')
1498+
with open(distexe_c, 'w', encoding='utf-8') as ofile:
14981499
ofile.write(textwrap.dedent('''\
14991500
#include<stdio.h>
15001501
@@ -1528,6 +1529,8 @@ def dist_impl(self, vcs_init, vcs_add_all=None, include_subprojects=True):
15281529
self.assertPathDoesNotExist(gz_checksumfile)
15291530
self.assertPathDoesNotExist(zip_distfile)
15301531
self.assertPathDoesNotExist(zip_checksumfile)
1532+
# update a source file timestamp; dist should succeed anyway
1533+
os.utime(distexe_c)
15311534
self._run(self.meson_command + ['dist', '--formats', 'bztar'],
15321535
workdir=self.builddir)
15331536
self.assertPathExists(bz_distfile)

0 commit comments

Comments
 (0)