msubprojects: fix potential error when resetting a git checkout

Untracked files need to be stashed too, or resetting may fail when
trying to (re-)apply a patch that adds one of those untracked files.
pull/11497/head
Benoit Pierre 2 years ago committed by Xavier Claessens
parent 93c11f2494
commit 8da060706c
  1. 9
      mesonbuild/msubprojects.py
  2. 11
      unittests/subprojectscommandtests.py

@ -207,13 +207,16 @@ class Runner:
self.log(self.git_output(cmd)) self.log(self.git_output(cmd))
def git_stash(self) -> None: def git_stash(self) -> None:
# That git command return 1 (failure) when there is something to stash. # That git command return some output when there is something to stash.
# We don't want to stash when there is nothing to stash because that would # We don't want to stash when there is nothing to stash because that would
# print spurious "No local changes to save". # print spurious "No local changes to save".
if not quiet_git(['diff', '--quiet', 'HEAD'], self.repo_dir)[0]: if quiet_git(['status', '--porcelain', ':!/.meson-subproject-wrap-hash.txt'], self.repo_dir)[1].strip():
# Don't pipe stdout here because we want the user to see their changes have # Don't pipe stdout here because we want the user to see their changes have
# been saved. # been saved.
self.git_verbose(['stash']) # Note: `--all` is used, and not `--include-untracked`, to prevent
# a potential error if `.meson-subproject-wrap-hash.txt` matches a
# gitignore pattern.
self.git_verbose(['stash', 'push', '--all', ':!/.meson-subproject-wrap-hash.txt'])
def git_show(self) -> None: def git_show(self) -> None:
commit_message = self.git_output(['show', '--quiet', '--pretty=format:%h%n%d%n%s%n[%an]']) commit_message = self.git_output(['show', '--quiet', '--pretty=format:%h%n%d%n%s%n[%an]'])

@ -177,6 +177,17 @@ class SubprojectsCommandTests(BasePlatformTests):
self.assertEqual(self._git_local_commit(subp_name), self._git_remote_commit(subp_name, 'newbranch')) self.assertEqual(self._git_local_commit(subp_name), self._git_remote_commit(subp_name, 'newbranch'))
self.assertTrue(self._git_local(['stash', 'list'], subp_name)) self.assertTrue(self._git_local(['stash', 'list'], subp_name))
# Untracked files need to be stashed too, or (re-)applying a patch
# creating one of those untracked files will fail.
untracked = self.subprojects_dir / subp_name / 'untracked.c'
untracked.write_bytes(b'int main(void) { return 0; }')
self._subprojects_cmd(['update', '--reset'])
self.assertTrue(self._git_local(['stash', 'list'], subp_name))
assert not untracked.exists()
# Ensure it was indeed stashed, and we can get it back.
self.assertTrue(self._git_local(['stash', 'pop'], subp_name))
assert untracked.exists()
# Create a new remote tag and update the wrap file. Checks that # Create a new remote tag and update the wrap file. Checks that
# "meson subprojects update --reset" checkout the new tag in detached mode. # "meson subprojects update --reset" checkout the new tag in detached mode.
self._git_create_remote_tag(subp_name, 'newtag') self._git_create_remote_tag(subp_name, 'newtag')

Loading…
Cancel
Save