瀏覽代碼

change git.py

liushuai 3 月之前
父節點
當前提交
c1ebdc1266
共有 1 個文件被更改,包括 12 次插入7 次删除
  1. 12 7
      preset/app/git.py

+ 12 - 7
preset/app/git.py

@@ -62,22 +62,27 @@ def activeBranch(localRep):
     return porcelain.active_branch(localRep)
 
 
-def checkout(localRep, branch, progStream=None):
+def checkout(localRep, branch, force=True, progStream=None):
     r = Repo(localRep)
     if progStream is None:
         progStream = NoneStream()
     try:
-        porcelain.checkout_branch(r, 'origin/' + branch, outstream=progStream)
+        porcelain.checkout_branch(r, 'origin/' + branch, force=force, outstream=progStream)
     except porcelain.CheckoutError as e:
         print("CheckoutError:", e)
-        porcelain.reset(r, 'hard')
-        porcelain.checkout_branch(r, 'origin/' + branch, outstream=progStream)
+        porcelain.fetch(localRep)
+        porcelain.checkout_branch(r, 'origin/' + branch, force=force, outstream=progStream)
 
-
-def pull(localRep, progStream=None, depth=3):
+ 
+def pull(localRep, progStream=None, force=True, depth=3):
     if progStream is None:
         progStream = NoneStream()
-    porcelain.pull(localRep, refspecs=porcelain.active_branch(localRep), outstream=progStream, depth=depth)
+    try:
+        porcelain.pull(localRep, refspecs=porcelain.active_branch(localRep), force=force, outstream=progStream, depth=depth)
+    except porcelain.CheckoutError as e:
+        print("CheckoutError:", e)
+        porcelain.fetch(localRep)
+        porcelain.pull(localRep, refspecs=porcelain.active_branch(localRep), force=force, outstream=progStream, depth=depth)
 
 
 def reset(localRep):