Allow git.checkout() to work on unmerged indexes
[stgit] / stgit / git.py
index 71bddca..6b14a74 100644 (file)
@@ -272,9 +272,11 @@ def rev_parse(git_id):
 def branch_exists(branch):
     """Existence check for the named branch
     """
-    for line in _output_lines(['git-rev-parse', '--symbolic', '--all']):
+    for line in _output_lines('git-rev-parse --symbolic --all 2>&1'):
         if line.strip() == branch:
             return True
+        if re.compile('[ |/]'+branch+' ').search(line):
+            raise GitException, 'Bogus branch: %s' % line
     return False
 
 def create_branch(new_branch, tree_id = None):
@@ -598,13 +600,19 @@ def barefiles(rev1, rev2):
 
     return result.rstrip()
 
+def pretty_commit(commit_id = 'HEAD'):
+    """Return a given commit (log + diff)
+    """
+    return _output(['git-diff-tree', '--cc', '--always', '--pretty', '-r',
+                    commit_id])
+
 def checkout(files = None, tree_id = None, force = False):
     """Check out the given or all files
     """
     if not files:
         files = []
 
-    if tree_id and __run('git-read-tree -m', [tree_id]) != 0:
+    if tree_id and __run('git-read-tree', [tree_id]) != 0:
         raise GitException, 'Failed git-read-tree -m %s' % tree_id
 
     checkout_cmd = 'git-checkout-index -q -u'
@@ -643,17 +651,17 @@ def reset(files = None, tree_id = None, check_out = True):
 
 def pull(repository = 'origin', refspec = None):
     """Pull changes from the remote repository. At the moment, just
-    use the 'git pull' command
+    use the 'git-pull' command
     """
-    # 'git pull' updates the HEAD
+    # 'git-pull' updates the HEAD
     __clear_head_cache()
 
     args = [repository]
     if refspec:
         args.append(refspec)
 
-    if __run('git pull', args) != 0:
-        raise GitException, 'Failed "git pull %s"' % repository
+    if __run('git-pull', args) != 0:
+        raise GitException, 'Failed "git-pull %s"' % repository
 
 def apply_patch(filename = None, base = None):
     """Apply a patch onto the current or given index. There must not
@@ -687,10 +695,10 @@ def apply_patch(filename = None, base = None):
 
 def clone(repository, local_dir):
     """Clone a remote repository. At the moment, just use the
-    'git clone' script
+    'git-clone' script
     """
-    if __run('git clone', [repository, local_dir]) != 0:
-        raise GitException, 'Failed "git clone %s %s"' \
+    if __run('git-clone', [repository, local_dir]) != 0:
+        raise GitException, 'Failed "git-clone %s %s"' \
               % (repository, local_dir)
 
 def modifying_revs(files, base_rev):