Skip to content

Commit 10a34a9

Browse files
committed
Fix update common script
1 parent 032148a commit 10a34a9

File tree

2 files changed

+43
-6
lines changed

2 files changed

+43
-6
lines changed

Scripts/UpdateCommon.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,12 @@ def UpdateGitHubRepo(repoRootUrl, location, commit):
110110

111111
print("Directory " + targetPath + " does not exist. \n\tUsing 'git clone' to get from " + ghRepoSource)
112112
sys.stdout.flush()
113-
try:
114-
subprocess.check_call(["git", "-C", scriptRoot, "clone", ghRepoSource, targetPath, "--branch", reqdCommit], shell=SHELLARG)
115-
except subprocess.CalledProcessError as e:
116-
print("'git clone' failed with returncode: %d\n" % e.returncode)
113+
114+
if False == GpaUtils.CloneGitRepo(ghRepoSource, reqdCommit, targetPath):
117115
sys.exit(1)
118-
sys.stderr.flush()
119-
sys.stdout.flush()
116+
117+
if reqdCommit is not None:
118+
GpaUtils.SwitchToBranchOrRef(targetPath, reqdCommit)
120119

121120
def ShowRevisions():
122121
repos_revision_map={}

Scripts/gpa_utils.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@
99
import subprocess
1010
import urllib
1111

12+
SHELLARG = False
13+
# The environment variable SHELL is only set for Cygwin or Linux
14+
SHELLTYPE = os.environ.get('SHELL')
15+
if ( SHELLTYPE == None ):
16+
# running on windows under default shell
17+
SHELLARG = True
18+
1219
if sys.version_info.major == 3:
1320
import urllib.request
1421

@@ -74,3 +81,34 @@ def Download(source_url, dest_dir, file_name):
7481
else:
7582
print("Unable to download file")
7683
return False
84+
85+
def SwitchToBranchOrRef(localrepopath, branch_or_ref):
86+
if os.path.isdir(localrepopath):
87+
currentDir = os.getcwd()
88+
os.chdir(localrepopath)
89+
commandArgs = ["git", "checkout", branch_or_ref]
90+
try:
91+
sys.stdout.flush()
92+
p = subprocess.check_call(commandArgs, shell=SHELLARG)
93+
sys.stdout.flush()
94+
sys.stderr.flush()
95+
os.chdir(currentDir)
96+
except subprocess.CalledProcessError as e:
97+
print ("'git clone' failed with returncode: %d\n" % e.returncode)
98+
os.chdir(currentDir)
99+
sys.stderr.flush()
100+
sys.exit(1)
101+
102+
def CloneGitRepo(remote, branch, target):
103+
target = os.path.normpath(target)
104+
commandArgs = ["git", "clone", remote, target]
105+
try:
106+
sys.stdout.flush()
107+
subprocess.check_call(commandArgs, shell=SHELLARG)
108+
sys.stdout.flush()
109+
sys.stderr.flush()
110+
return True
111+
except subprocess.CalledProcessError as e:
112+
print ("'git clone' failed with returncode: %d\n" % e.returncode)
113+
sys.stderr.flush()
114+
return False

0 commit comments

Comments
 (0)