[PATCH 1/2] stgit: ignore submodules when checking if working tree is clean

12 views
Skip to first unread message

Jacob Keller

unread,
Nov 15, 2017, 5:26:57 AM11/15/17
to st...@googlegroups.com, Jacob Keller
If a patch contains a change to a submodule, and a user attempts to pop
and then push the patch from the queue, errors similar to the following
can occur:

$stg pop
Popped a-new-patch
No patch applied
$stg push
stg push: Worktree not clean. Use "refresh" or "reset --hard"

This error occurs because after popping the patch off the queue, the
submodule contents are not updated. This is due to the way that git
treats submodules and does not recursively check them out.

Later, once we go to push the patch back on, we check if the working
tree is clean, by using update-index. Since the submodule remained
checked out at the previous location, we now complain. Worse yet, the
two suggestions we've given do not help.

First, if the user tries to "reset --hard" to throw away these changes,
nothing happens. This, again, is because the submodule is not
automatically moved. Thus, the user can try running reset --hard as many
time as they like, and it will not resolve the problem.

Second, the user can use refresh. This is actually worse, because it
will superficially appear to resolve the problem. The refresh will
simply merge in this submodule pointer change into the previous patch on
the queue. Now, the user can continue with the push, which will notice
the submodule change was already part of the previous patch from the
queue and will essentially remove it from the original patch.

This is much worse now, we've accidentally moved the submodule change to
the wrong patch!

This issue and similar other issues exist due to the default way
submodules behave. We can fix all of them by telling "git update-index"
to ignore submodules. Doing so, now it will not consider submodules
which aren't checked out correctly as a problem for a dirty working
tree. This solves the problem, and makes stgit behave more how git
itself behaves with submodules by default.

Signed-off-by: Jacob Keller <jacob.e...@intel.com>
---
stgit/lib/git.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/stgit/lib/git.py b/stgit/lib/git.py
index e9d9856d0522..82b7a900afb7 100644
--- a/stgit/lib/git.py
+++ b/stgit/lib/git.py
@@ -1086,7 +1086,7 @@ class IndexAndWorktree(RunWithEnvCwd):
def worktree_clean(self):
"""Check whether the worktree is clean relative to index."""
try:
- self.run(['git', 'update-index', '--refresh']).discard_output()
+ self.run(['git', 'update-index', '--ignore-submodules', '--refresh']).discard_output()
except RunException:
return False
else:
--
2.15.0

Reply all
Reply to author
Forward
0 new messages