Update the README (mainly alignment)
[stgit] / stgit / git.py
index fe2c447..9d8cdf0 100644 (file)
@@ -94,7 +94,6 @@ def get_conflicts():
 def _input(cmd, file_desc):
     p = popen2.Popen3(cmd)
     for line in file_desc:
-        print line
         p.tochild.write(line)
     p.tochild.close()
     if p.wait():
@@ -420,18 +419,21 @@ def files(rev1, rev2):
 
     return str.rstrip()
 
-def checkout(files = [], force = False):
+def checkout(files = [], tree_id = None, force = False):
     """Check out the given or all files
     """
-    git_flags = 'git-checkout-cache -q -u'
+    if tree_id and __run('git-read-tree -m', [tree_id]) != 0:
+        raise GitException, 'Failed git-read-tree -m %s' % tree_id
+
+    checkout_cmd = 'git-checkout-cache -q -u'
     if force:
-        git_flags += ' -f'
+        checkout_cmd += ' -f'
     if len(files) == 0:
-        git_flags += ' -a'
+        checkout_cmd += ' -a'
     else:
-        git_flags += ' --'
+        checkout_cmd += ' --'
 
-    if __run(git_flags, files) != 0:
+    if __run(checkout_cmd, files) != 0:
         raise GitException, 'Failed git-checkout-cache'
 
 def switch(tree_id):
@@ -440,17 +442,14 @@ def switch(tree_id):
     to_delete = filter(lambda x: x[0] in ['N', 'A'],
                        __tree_status(tree_id = tree_id))
 
-    if __run('git-read-tree -m', [tree_id]) != 0:
-        raise GitException, 'Failed git-read-tree -m %s' % tree_id
-
-    checkout(force = True)
+    checkout(tree_id = tree_id, force = True)
     __set_head(tree_id)
 
     # checkout doesn't remove files
     for fs in to_delete:
         os.remove(fs[1])
 
-def fetch(location, head = None, tag = None):
+def pull(location, head = None, tag = None):
     """Fetch changes from the remote repository. At the moment, just
     use the 'git fetch' scripts
     """
@@ -460,11 +459,9 @@ def fetch(location, head = None, tag = None):
     elif tag:
         args += ['tag', tag]
 
-    if __run('git fetch', args) != 0:
+    if __run('git pull', args) != 0:
         raise GitException, 'Failed "git fetch %s"' % location
 
-    return read_string(os.path.join(base_dir, 'FETCH_HEAD'))
-
 def apply_patch(filename = None):
     """Apply a patch onto the current index. There must not be any
     local changes in the tree, otherwise the command fails
@@ -476,3 +473,11 @@ def apply_patch(filename = None):
             raise GitException, 'Patch does not apply cleanly'
     else:
         _input('git-apply --index', sys.stdin)
+
+def clone(repository, local_dir):
+    """Clone a remote repository. At the moment, just use the
+    'git clone' script
+    """
+    if __run('git clone', [repository, local_dir]) != 0:
+        raise GitException, 'Failed "git clone %s %s"' \
+              % (repository, local_dir)