[PATCH v2] Fix stale git status



Recent commit 84524f7f2be4722f206e77e3d8fc8acb25de7fea replaced the use
of "git status" with the lower-level "git diff-index".  However, when
using "git diff-index" we need to explicitly update the index prior
to running "git diff-index".  Previously, "git status" would
automatically update the index prior to diffing.

If the index is not explicitly updated, meld reports incorrect
file status in certain scenarios.  For example, running:
 - sed -i 's/firefox/chrome/' GNUMakefile
 - git diff (update git's index)
 - sed -i 's/chrome/firefox/' GNUMakefile (git's index is now out of date)
 - bin/meld ./

Meld will then show GNUMakefile as being modified even though its contents
are actually unchanged.

Calling "git update-index --refresh" prior to "git diff-index" resolves
the previous stale status issue.

Signed-off-by: Peter Tyser <ptyser gmail com>
---
Changes since v1:
- Use _vc.popen() instead of os.system() for consistency's sake.  This
  also has the side benefit of eating the stdout output of the
  'git update-index' command.

 meld/vc/git.py |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/meld/vc/git.py b/meld/vc/git.py
index 479710b..a3b69c6 100644
--- a/meld/vc/git.py
+++ b/meld/vc/git.py
@@ -74,6 +74,9 @@ class Vc(_vc.CachedVc):
     def _lookup_tree_cache(self, rootdir):
         while 1:
             try:
+                # Update the index before getting status, otherwise we could
+                # be reading stale status information
+                _vc.popen(["git", "update-index", "--refresh"])
                 proc = _vc.popen([self.CMD, "diff-index", "--name-status", \
                     "HEAD", "./"], cwd=self.location)
                 entries = proc.read().split("\n")[:-1]
-- 
1.6.2-rc2.GIT



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]