-
Notifications
You must be signed in to change notification settings - Fork 0
/
1-git_clone_picongpu.py
executable file
·44 lines (37 loc) · 1.81 KB
/
1-git_clone_picongpu.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import os
import subprocess
import sys
# Function to check if the repo is cloned
def check_and_clone_repo(picongpu_git_path, picongpu_local_dir):
print(f"Current working directory: {os.getcwd()}") # Log the current working directory
if not os.path.isdir(picongpu_local_dir):
print(f"Cloning PIConGPU repository from {picongpu_git_path} into {picongpu_local_dir}...")
subprocess.run(['git', 'clone', picongpu_git_path, picongpu_local_dir], stdout=sys.stdout, stderr=subprocess.STDOUT)
else:
print(f"PIConGPU repository already exists in {picongpu_local_dir}. Checking for updates...")
os.chdir(picongpu_local_dir)
subprocess.run(['git', 'fetch', 'origin'], stdout=sys.stdout, stderr=subprocess.STDOUT)
default_branch = subprocess.check_output(
["git", "remote", "show", "origin"],
universal_newlines=True
).splitlines()
# Find default branch name
for line in default_branch:
if "HEAD branch" in line:
default_branch_name = line.split(":")[1].strip()
break
else:
print("Unable to determine the default branch. Exiting...")
return
print(f"Pulling the latest changes from the {default_branch_name} branch...")
subprocess.run(['git', 'pull', 'origin', default_branch_name], stdout=sys.stdout, stderr=subprocess.STDOUT)
# Main function
def main():
if len(sys.argv) != 3:
print("Error: Please provide the git URL and repo directory.")
sys.exit(1)
picongpu_git_path = sys.argv[1] # Get the git URL from command-line argument
picongpu_local_dir = sys.argv[2] # Get the repo directory from command-line argument
check_and_clone_repo(picongpu_git_path, picongpu_local_dir)
if __name__ == '__main__':
main()