Skip to content

Commit

Permalink
added decoding for special characters in git branch names (#496)
Browse files Browse the repository at this point in the history
* added decoding for special characters in git branch names

Signed-off-by: MathiasAugstein <[email protected]>

* added test cases for special character decoding

Signed-off-by: MathiasAugstein <[email protected]>

* Added information to Readme

Signed-off-by: MathiasAugstein <[email protected]>

---------

Signed-off-by: MathiasAugstein <[email protected]>
  • Loading branch information
MathiasAugstein authored May 22, 2023
1 parent 12384ee commit 1328004
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
3 changes: 2 additions & 1 deletion git_resource/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. `[email protected]/path/to/repo.git#myBranchNameHere`).
If passing a repo url, a branch may be specified with a hash delimiter (i.e. `[email protected]/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. `[email protected]/path/to/repo.git#tags/v1.0.01`)
To use a specific revision/sha, prefix the sha with `@` (i.e. `[email protected]/path/to/repo.git@myRevisionSha`).
If no branch or revision is specified, defaults to `master`
Expand Down
6 changes: 5 additions & 1 deletion git_resource/Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
8 changes: 8 additions & 0 deletions git_resource/test/Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ url_test_cases = [
url="[email protected]/path/to/repo.git",
repo="repo",
tree="#myBranchNameHere"),
_case(input='[email protected]/path/to/repo.git#myBranch%23Name%40Here',
url="[email protected]/path/to/repo.git",
repo="repo",
tree="#myBranch#Name@Here"),
_case(input='https://[email protected]/path/repo.git',
url='https://[email protected]/path/repo.git',
repo='repo',
Expand All @@ -39,6 +43,10 @@ url_test_cases = [
url='https://[email protected]/path/repo.git',
repo='repo',
tree='@myRevisionSha'),
_case(input='https://[email protected]/path/repo.git@my%23Revision%40Sha',
url='https://[email protected]/path/repo.git',
repo='repo',
tree='@my#Revision@Sha'),
]

if os.name == 'nt':
Expand Down

0 comments on commit 1328004

Please sign in to comment.