Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding foreach to pull-submodules.py #320

Merged
merged 5 commits into from
Nov 9, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 48 additions & 67 deletions pull-submodules.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,10 @@ def main():
if (not exclude and url.find("github") != -1) or (
url.find("lfna.unizar.es") != -1 and lfna) or (
url.find("gitlab.pandax.sjtu.edu.cn") != -1 and sjtu):
print("Pulling: ", end="")
print("Updating submodule: ", end="")
print(fullpath.rstrip(), end='')
# init
p = subprocess.run(f"cd {root} && git submodule init {submodule}", #
p = subprocess.run(f"cd {root} && git submodule update --init {submodule}", #
shell=True,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if debug:
Expand All @@ -179,78 +179,59 @@ def main():
if p.stdout.decode("utf-8").find("checkout") >= 0:
print(p.stdout.decode("utf-8"))
errorOutput = p.stderr.decode("utf-8")
if errorOutput.find("failed") != -1 or errorOutput.find("error") != -1:
if errorOutput.find("failed") != -1 or errorOutput.find("error") != -1 or errorOutput.find("ERROR") != -1 or errorOutput.find("fatal") != -1:
print("[\033[91m Failed \x1b[0m]")
if debug:
print("Message: ")
print(errorOutput)
continue
# if 'force', override the changes with git reset
if force:
p = subprocess.run(f"cd {root}/{submodule} && git reset --hard", #
shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if debug:
print(p.stdout.decode("utf-8"))
print(p.stderr.decode("utf-8"))
errorOutput = p.stderr.decode("utf-8")
if errorOutput.find("failed") != -1 or errorOutput.find("error") != -1:
print("[\033[91m Failed \x1b[0m]")
if debug:
print("Message: ")
print(errorOutput)
continue
# update submodule
p = subprocess.run(f"cd {root} && git submodule update {submodule}", #
shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if debug:
print(p.stdout.decode("utf-8"))
print(p.stderr.decode("utf-8"))
if p.stdout.decode("utf-8").find("checkout") >= 0:
print(p.stdout.decode("utf-8"))
errorOutput = p.stderr.decode("utf-8")
if errorOutput.find("failed") != -1 or errorOutput.find("error") != -1:
print("[\033[91m Failed \x1b[0m]")
if debug:
print("Message: ")
print(errorOutput)
continue
# if latest, pull the latest commit instead of the one recorded in the main repo
if latest:
branchExistsPcs = subprocess.run(
f"git ls-remote --heads {url} {frameworkBranchName} | wc -l", #
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)

branchToPull = "master"
if branchExistsPcs.stdout.decode("utf-8").rstrip("\n") != "0":
branchToPull = frameworkBranchName
print(f" --> Pulling branch: {branchToPull}", end='')

p = subprocess.run(
f"cd {root}/{submodule} && git fetch && git checkout {branchToPull} && git pull origin {branchToPull}", #
shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if debug:
print(p.stdout.decode("utf-8"))
print(p.stderr.decode("utf-8"))
errorOutput = p.stderr.decode("utf-8")
if errorOutput.find("failed") != -1 or errorOutput.find("error") != -1:
print("[\033[91m Failed \x1b[0m]")
if debug:
print("Message: ")
print(errorOutput)
continue
# get commit id
p = subprocess.run(f"cd {root}/{submodule} && git rev-parse HEAD", #
shell=True,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
else:
print("[\033[92m OK \x1b[0m]")

if errorOutput.find("failed") == -1 and errorOutput.find("error") == -1:
print("[\033[92m OK \x1b[0m] (" + p.stdout.decode("utf-8")[0:7] + ")")
# back to the git framework directory
p = subprocess.run(f"cd {root}", #
shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
# if 'force', override the changes with git reset
if force:
print("Forcing reset: ", end="")
p = subprocess.run(f"git submodule foreach 'git reset --hard'", #
shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if debug:
print(p.stdout.decode("utf-8"))
print(p.stderr.decode("utf-8"))
errorOutput = p.stderr.decode("utf-8")
if errorOutput.find("failed") != -1 or errorOutput.find("error") != -1 or errorOutput.find("ERROR") != -1 or errorOutput.find("fatal") != -1:
print("[\033[91m Failed \x1b[0m]")
if debug:
print("Message: ")
print(errorOutput)
else:
print("[\033[92m OK \x1b[0m]")

# if latest, pull the latest commit instead of the one recorded in the main repo
if latest:
print("Pulling submodules: ", end="")
p = subprocess.run(f"git submodule foreach 'git fetch; if [ -z \"$(git ls-remote --heads origin {frameworkBranchName})\" ]; then git checkout master; else git checkout {frameworkBranchName};fi;git pull'", #
shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if debug:
print(p.stdout.decode("utf-8"))
print(p.stderr.decode("utf-8"))
errorOutput = p.stderr.decode("utf-8")
if errorOutput.find("failed") != -1 or errorOutput.find("error") != -1 or errorOutput.find("ERROR") != -1 or errorOutput.find("fatal") != -1:
print("[\033[91m Failed \x1b[0m]")
if debug:
print("Message: ")
print(errorOutput)
else:
print("[\033[92m OK \x1b[0m]")
# get commit id
p = subprocess.run(f"git submodule foreach 'git rev-parse HEAD'", #
shell=True,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
print(p.stdout.decode("utf-8"))

if clean:
subprocess.run("git clean -xfd", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
subprocess.run("git reset --hard", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
subprocess.run(f"git clean -xfd", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
subprocess.run(f"git reset --hard", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)


if __name__ == "__main__":
Expand Down