Browse Source

push前先pull

liuyuqi-dellpc 1 year ago
parent
commit
8bd1679d12

+ 4 - 0
repo_sync/platform/coding/coding.py

@@ -201,6 +201,10 @@ class CodingIE(BasePlatform):
         os.system(
             f'git remote add origin_coding https://{self.username}:{self.token}@e.coding.net/{self.username}/{self.project_name}/{repo_name}.git'
         )
+        result = subprocess.run(['git', 'symbolic-ref', '--short', 'HEAD'], capture_output=True, text=True)
+        current_branch = result.stdout.strip()
+        os.system(f'git pull origin_gogs {current_branch}')
+        
         os.system('git push -u origin_coding')
         os.system('git remote remove origin_coding')
         os.chdir('..')

+ 4 - 0
repo_sync/platform/gitee.py

@@ -98,6 +98,10 @@ class GiteeIE(BasePlatform):
         os.system(
             f'git remote add origin_gitee https://{self.username}:{self.token}@gitee.com/{self.username}/{repo_name}.git'
         )
+        result = subprocess.run(['git', 'symbolic-ref', '--short', 'HEAD'], capture_output=True, text=True)
+        current_branch = result.stdout.strip()
+        os.system(f'git pull origin_gogs {current_branch}')
+        
         os.system('git push -u origin_gitee')
         os.system('git remote remove origin_gitee')
         os.chdir('..')

+ 4 - 0
repo_sync/platform/github.py

@@ -104,6 +104,10 @@ class GithubIE(BasePlatform):
         os.system(
             f'git remote add origin_github https://{self.username}:{self.token}@github.com/{self.username}/{repo_name}.git'
         )
+        result = subprocess.run(['git', 'symbolic-ref', '--short', 'HEAD'], capture_output=True, text=True)
+        current_branch = result.stdout.strip()
+        os.system(f'git pull origin_gogs {current_branch}')
+        
         os.system('git push -u origin_github')
         os.system('git remote remove origin_github')
         os.chdir('..')

+ 4 - 0
repo_sync/platform/gitlab.py

@@ -123,6 +123,10 @@ class GitlabIE(BasePlatform):
         os.system(
             f"git remote add origin_gitlab https://{self.username}:{self.token}@{pur_host}/{self.username}/{repo_name}.git"
         )
+        result = subprocess.run(['git', 'symbolic-ref', '--short', 'HEAD'], capture_output=True, text=True)
+        current_branch = result.stdout.strip()
+        os.system(f'git pull origin_gogs {current_branch}')
+        
         os.system("git push -u origin_gitlab")
         os.system("git remote remove origin_gitlab")
         os.chdir("..")

+ 3 - 3
repo_sync/platform/gogs.py

@@ -91,8 +91,6 @@ class GogsIE(BasePlatform):
             local_repo_path = local_repo_path[:-1]
         repo_name = local_repo_path.split(os.path.sep)[-1]
         print(f'pull repo:{self.username}/{repo_name} from {self._host}')
-        self.create_repo(repo_name)
-
         pur_host = re.search(r'(?<=//)[^/]+', self._host).group()
 
         os.chdir(local_repo_path)
@@ -111,7 +109,6 @@ class GogsIE(BasePlatform):
             local_repo_path = local_repo_path[:-1]
         repo_name = local_repo_path.split(os.path.sep)[-1]
         print(f'push repo:{self.username}/{repo_name} to {self._host}')
-        self.create_repo(repo_name)
 
         pur_host = re.search(r'(?<=//)[^/]+', self._host).group()
 
@@ -120,6 +117,9 @@ class GogsIE(BasePlatform):
         os.system(
             f'git remote add origin_gogs https://{self.username}:{self.token}@{pur_host}/{self.username}/{repo_name}.git'
         )
+        result = subprocess.run(['git', 'symbolic-ref', '--short', 'HEAD'], capture_output=True, text=True)
+        current_branch = result.stdout.strip()
+        os.system(f'git pull origin_gogs {current_branch}')
         os.system('git push -u origin_gogs')
         os.system('git remote remove origin_gogs')
         os.chdir('..')