aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xmesonbuild/msubprojects.py9
-rw-r--r--unittests/subprojectscommandtests.py11
2 files changed, 17 insertions, 3 deletions
diff --git a/mesonbuild/msubprojects.py b/mesonbuild/msubprojects.py
index 1be8543..091f1eb 100755
--- a/mesonbuild/msubprojects.py
+++ b/mesonbuild/msubprojects.py
@@ -207,13 +207,16 @@ class Runner:
self.log(self.git_output(cmd))
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
# 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
# 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:
commit_message = self.git_output(['show', '--quiet', '--pretty=format:%h%n%d%n%s%n[%an]'])
diff --git a/unittests/subprojectscommandtests.py b/unittests/subprojectscommandtests.py
index bca124d..d50828b 100644
--- a/unittests/subprojectscommandtests.py
+++ b/unittests/subprojectscommandtests.py
@@ -177,6 +177,17 @@ class SubprojectsCommandTests(BasePlatformTests):
self.assertEqual(self._git_local_commit(subp_name), self._git_remote_commit(subp_name, 'newbranch'))
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
# "meson subprojects update --reset" checkout the new tag in detached mode.
self._git_create_remote_tag(subp_name, 'newtag')