[jhbuild] [git] Introduce a predicate execution wrapper



commit d8b5319bc2f5501536dbea64f5b2d7960afff6b8
Author: Dirk Wallenstein <halsmit t-online de>
Date:   Sun May 16 12:36:20 2010 +0200

    [git] Introduce a predicate execution wrapper
    
    There are often git commands where only a boolean return value is of
    interest. This new wrapper can be easily used to create such predicates.

 jhbuild/versioncontrol/git.py |   15 +++++++++++++++
 1 files changed, 15 insertions(+), 0 deletions(-)
---
diff --git a/jhbuild/versioncontrol/git.py b/jhbuild/versioncontrol/git.py
index 69e1720..1c222d9 100644
--- a/jhbuild/versioncontrol/git.py
+++ b/jhbuild/versioncontrol/git.py
@@ -157,6 +157,21 @@ class GitBranch(Branch):
         return self.branch
     branchname = property(branchname)
 
+    def _execute_git_predicate(self, predicate):
+        """A git command wrapper for the cases, where only the boolean outcome
+        is of interest.
+        """
+        try:
+            get_output(predicate, cwd=self.get_checkoutdir(),
+                    extra_env=get_git_extra_env())
+        except CommandError:
+            return False
+        return True
+
+    def _is_inside_work_tree(self):
+        return self._execute_git_predicate(
+                ['git', 'rev-parse', '--is-inside-work-tree'])
+
     def get_current_branch(self):
         for line in get_output(['git', 'branch'],
                 cwd=self.get_checkoutdir(), extra_env=get_git_extra_env()).splitlines():



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