diff --git a/git_resource/README.md b/git_resource/README.md index 444f88ace..d4f8b456c 100644 --- a/git_resource/README.md +++ b/git_resource/README.md @@ -26,7 +26,8 @@ git_resource(resource_name, path_or_repo, dockerfile='Dockerfile', namespace='de * `resource_name` ( str ) – the name to use for this resource * `path_or_repo` ( str ) – either the URL to the remote git repo, or the path to your local checkout. -If passing a repo url, a branch may be specified with a hash delimiter (i.e. `git@example.com/path/to/repo.git#myBranchNameHere`). +If passing a repo url, a branch may be specified with a hash delimiter (i.e. `git@example.com/path/to/repo.git#myBranchNameHere`). +In case the branch name contains a `#` or a `@` you can escape them with the according URL encodings `%23` and `%40`, respectively. To use a tag, prefix the tag name with `tags/` (i.e. `git@example.com/path/to/repo.git#tags/v1.0.01`) To use a specific revision/sha, prefix the sha with `@` (i.e. `git@example.com/path/to/repo.git@myRevisionSha`). If no branch or revision is specified, defaults to `master` diff --git a/git_resource/Tiltfile b/git_resource/Tiltfile index 78b821960..8224878a7 100644 --- a/git_resource/Tiltfile +++ b/git_resource/Tiltfile @@ -147,7 +147,11 @@ def _parse_repository_url(url): repository_name = os.path.basename(url).rstrip('.git') - return url, repository_name, tree + return url, repository_name, simple_url_decode(tree) + +# in case the branch name contains '#' or '@', these need to be escaped +def simple_url_decode(tree): + return tree.replace('%23', '#').replace('%40', '@') def _get_default_checkout_target(repository_url): diff --git a/git_resource/test/Tiltfile b/git_resource/test/Tiltfile index 947064fd5..0422f51cd 100644 --- a/git_resource/test/Tiltfile +++ b/git_resource/test/Tiltfile @@ -27,6 +27,10 @@ url_test_cases = [ url="git@example.com/path/to/repo.git", repo="repo", tree="#myBranchNameHere"), + _case(input='git@example.com/path/to/repo.git#myBranch%23Name%40Here', + url="git@example.com/path/to/repo.git", + repo="repo", + tree="#myBranch#Name@Here"), _case(input='https://user@example.com/path/repo.git', url='https://user@example.com/path/repo.git', repo='repo', @@ -39,6 +43,10 @@ url_test_cases = [ url='https://user@example.com/path/repo.git', repo='repo', tree='@myRevisionSha'), + _case(input='https://user@example.com/path/repo.git@my%23Revision%40Sha', + url='https://user@example.com/path/repo.git', + repo='repo', + tree='@my#Revision@Sha'), ] if os.name == 'nt':