浏览代码

do not create local branches if they exist

Tobias Simetsreiter 5 年之前
父节点
当前提交
2e7bb0e734
共有 1 个文件被更改,包括 11 次插入5 次删除
  1. 11 5
      abe_setup.py

+ 11 - 5
abe_setup.py

@@ -1,5 +1,6 @@
 #!/usr/bin/env python3
-
+#
+# A script to setup a Working tree from abe git submodules
 
 DEBUG = 1
 
@@ -77,7 +78,7 @@ def clone_repo_cached( cache_dir=None, bare=False):
 
         if cache_dir != None:
             cache_repo_path = cache_path(cache_dir, origin.urls)
-            print('Cacheing from:', cache_repo_path) if DEBUG else None
+            print(f"Cacheing from: {cache_repo_path}") if DEBUG else None
             clone_repo_cached(cache_dir=None, bare=True)( cache_repo_path, remote, ref)
             if 'cache' in repo.remotes:
                 cache = repo.remotes['cache']
@@ -95,8 +96,12 @@ def clone_repo_cached( cache_dir=None, bare=False):
             print('Heads:', repo.heads) if DEBUG>1 else None
 
             if ref in repo.tags:
+                tracking_branch_name = 'local_tag_branch/'+ref
                 tracking_ref = repo.tags[ref]
-                active_branch = repo.create_head('local_tag_branch/'+ref, tracking_ref)
+                if tracking_branch_name in repo.heads:
+                    active_branch = repo.heads[tracking_branch_name]
+                else:
+                    active_branch = repo.create_head('local_tag_branch/'+ref, tracking_ref)
             elif ref in repo.heads:
                 tracking_ref = origin.refs[ref]
                 active_branch = repo.heads[ref]
@@ -112,9 +117,10 @@ def clone_repo_cached( cache_dir=None, bare=False):
             else:
                 try:
                     tracking_ref = ref
-                    active_branch = repo.create_head('local_commit_branch/'+tracking_ref, tracking_ref)
+                    tracking_branch_name = 'local_commit_branch/'+ref
+                    active_branch = repo.create_head(tracking_branch_name, tracking_ref)
                 except Exception:
-                    raise Exception(f"Branch/Tag/Commit {ref} not found")
+                    raise Exception(f"Branch/Tag/Commit \"{ref}\" not found")
             print('Active Branch:', active_branch) if DEBUG else None
             print('Tracking Ref:', tracking_ref, '\n') if DEBUG else None
             active_branch.checkout()