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

Add url normalization to generator command. #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
16 changes: 12 additions & 4 deletions k
Original file line number Diff line number Diff line change
Expand Up @@ -2015,15 +2015,23 @@ end
PRIVATE_METHODS_AFTER_COMMANDS = private_methods - PRIVATE_METHODS_BEFORE_COMMANDS

def verify_inside_context_repository!
context_repo_value = K_CONTEXT.fetch("repository").delete_suffix(".git")
current_repo_value = `git remote get-url origin`.strip.delete_suffix(".git")

context_repo = URI K_CONTEXT.fetch("repository").delete_suffix(".git")
current_repo = URI `git remote get-url origin`.strip.delete_suffix(".git")

unless context_repo.path == current_repo.path
unless normalized_git_url(current_repo_value).path == normalized_git_url(context_repo_value).path
abort "Error: this command must be run from a clone of the context repository (#{context_repo})"
end
end

def normalized_git_url(url)
case url
when /^git@/ then URI "https://" + url[4..].sub(":", "/").delete_suffix(".git") # Convert SSH URL to HTTPS URL
when /^https:\/\// then URI url.delete_suffix(".git") # Remove .git suffix from HTTPS URL
else
abort "Error: url not supported (#{url})"
end
end

def system_or_die(command)
system(command) || abort("Unsuccessful exit code while running `#{command}`")
end
Expand Down