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

Check for changed GenConfig remote URL and error out #13724

Merged
merged 2 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
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
17 changes: 16 additions & 1 deletion packages/framework/get_dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,23 @@ function tril_genconfig_clone_or_update_repo() {
echo

if [[ -d ${sub_dir} ]] ; then
echo "STATUS: ${sub_dir}: Fetching remote repo"
cd ${sub_dir}
# Validate correct remote and abort if not correct
remote=$(git remote get-url origin)
normalized_remote=$(python3 ${script_dir}/normalize_git_repo_url.py ${remote})
normalized_git_url=$(python3 ${script_dir}/normalize_git_repo_url.py ${git_url})
if [[ "${normalized_remote}" != "${normalized_git_url}" ]] ; then
echo "ERROR: Current remote origin does not match expected!" >&2
echo " Current Remote: ${remote}" >&2
echo " Expected Remote: ${git_url}" >&2
echo "" >&2
echo "Please remove/move '$(pwd)' and re-run this script" >&2
echo "" >&2
echo "" >&2
exit 1
fi
# Update remote repo (which points to correct remote)
echo "STATUS: ${sub_dir}: Fetching remote repo"
tril_genconfig_assert_pwd_is_git_repo
cmd="git fetch"
retry_command "${cmd}"
Expand Down
36 changes: 36 additions & 0 deletions packages/framework/normalize_git_repo_url.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env python3

import sys

def removeStartingSubstr(inputStr, substrToRemove):
if inputStr.startswith(substrToRemove):
substrToRemoveLen = len(substrToRemove)
return inputStr[substrToRemoveLen:]
return inputStr

def removeTrailingSubstr(inputStr, substrToRemove):
if inputStr.endswith(substrToRemove):
substrToRemoveLen = len(substrToRemove)
return inputStr[:-substrToRemoveLen]
return inputStr

def normalizeGitRepoUrl(inputUrl):
url = inputUrl
url = removeStartingSubstr(url, "https://")
url = removeStartingSubstr(url, "git@")
url = removeTrailingSubstr(url, ".git")
url = url.replace(":", "/")
url = url.lower()
return url

# Main

def main():
if len(sys.argv) != 2:
print("Usage: normalize_git_repo_url.py <string>")
sys.exit(1)
inputUrl = sys.argv[1]
print(normalizeGitRepoUrl(inputUrl))

if __name__ == "__main__":
main()
Loading