[jhbuild] [git] Use a new predicate to determine the need to stash



commit a7ca3e62fe2c3ad7111d85813c277b169d23bda6
Author: Dirk Wallenstein <halsmit t-online de>
Date:   Sun May 16 13:27:44 2010 +0200

    [git] Use a new predicate to determine the need to stash
    
    Introduce a predicate to test if the repository is dirty, optionally
    including existing submodules.
    
    This function is used to recognize uncommited changes to be stashed.
    This should now work more reliable in the face of changes in submodules,
    as the output of 'git diff --submodule' may have multiple lines, where
    not every line starts with 'Submodule '.
    
    To reliably exclude differences in submodules, a dependency to a two
    year old git version is added.

 jhbuild/versioncontrol/git.py |   20 +++++++++++---------
 1 files changed, 11 insertions(+), 9 deletions(-)
---
diff --git a/jhbuild/versioncontrol/git.py b/jhbuild/versioncontrol/git.py
index c393ec0..97c907a 100644
--- a/jhbuild/versioncontrol/git.py
+++ b/jhbuild/versioncontrol/git.py
@@ -179,6 +179,16 @@ class GitBranch(Branch):
         return self._execute_git_predicate(
                 ['git', 'config', '--get', current_branch_remote_config])
 
+    def is_dirty(self, ignore_submodules=True):
+        submodule_options = []
+        if ignore_submodules:
+            if not self._check_version_git('1.5.6'):
+                raise CommandError(_('Need at least git-1.5.6 from June/08 '
+                        'to operate'))
+            submodule_options = ['--ignore-submodules']
+        return not self._execute_git_predicate(
+                ['git', 'diff', '--exit-code', '--quiet'] + submodule_options)
+
     def _check_version_git(self, version_spec):
         return check_version(['git', '--version'], r'git version ([\d.]+)',
                 version_spec, extra_env=get_git_extra_env())
@@ -299,16 +309,8 @@ class GitBranch(Branch):
         if update_mirror:
             self.update_dvcs_mirror(buildscript)
 
-        if self._check_version_git('1.7.0'):
-            git_diff_submodule = ['--submodule']
-        else:
-            git_diff_submodule = []
-
         stashed = False
-        git_diff_output = get_output(['git', 'diff'] + git_diff_submodule, **git_extra_args)
-        git_diff_output = '\n'.join([x for x in git_diff_output.splitlines() \
-                                     if not x.startswith('Submodule ')])
-        if git_diff_output:
+        if self.is_dirty(ignore_submodules=True):
             stashed = True
             buildscript.execute(['git', 'stash', 'save', 'jhbuild-stash'],
                     **git_extra_args)



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