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

emerge-gitclone: handle merged scripts repo #15

Merged
merged 2 commits into from
Mar 31, 2023
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
41 changes: 27 additions & 14 deletions emerge-gitclone
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,35 @@ def get_channel():
return channel


def git_clone_repo(repo_url, repo_location):
"""Clone the given repo at the given location"""
def git_clone_scripts(repo_url, repo_location, ref):
"""Clone the scripts repo at the given location, and handle submodules (if applicable)"""
print(f">>> Starting git clone in {repo_location}")
os.umask(0o022)
subprocess.check_call(
["git", "clone", "--recurse-submodules", repo_url, repo_location]
["git", "clone", repo_url, repo_location]
)

# Check if this ref uses submodules and check these out if it does.
subprocess.check_output(
["git", "-C", repo_location, "checkout", ref]
)
try:
with open(repo_location + '/.gitmodules') as gm:
gmc = gm.read()
if '[submodule ' in gmc:
print(f">>> Submodules detected in {ref}.")
subprocess.check_output(
["git", "-C", repo_location, "submodule", "init"]
)
subprocess.check_output(
["git", "-C", repo_location, "submodule", "update"]
)
else
print(f">>> Empty or invalid submodule config detected in {ref}")
print(f">>> at {repo_location}/.gitmodules. Ignoring and continuing w/o submodules.")
except (FileNotFoundError, IOError):
print(f">>> No submodules detected in {ref}. Assuming unified scripts repo.")

print(f">>> Git clone in {repo_location} successful")


Expand Down Expand Up @@ -74,21 +96,12 @@ def sync_repo():
os.unlink(GIT_LOCATION.format(repo=repo))

if repo == "scripts":
git_clone_repo(
git_clone_scripts(
repo_url=GIT_URI.format(repo=repo),
repo_location=GIT_LOCATION.format(repo=repo),
ref=ref
)

subprocess.check_output(
[
"git",
"-C",
GIT_LOCATION.format(repo=repo),
"checkout",
"--recurse-submodules",
ref,
]
)
else:
print(f">>> Symlink the repository with the appropriate folder - {repo}")
os.symlink(
Expand Down