-
-
Notifications
You must be signed in to change notification settings - Fork 209
feat(settings): custom shortcuts #1941
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
Open
noirbizarre
wants to merge
1
commit into
copier-org:master
Choose a base branch
from
noirbizarre:feat/shortcuts
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,12 +43,6 @@ def get_git_version() -> Version: | |
|
||
GIT_PREFIX = ("git@", "git://", "git+", "https://github.com/", "https://gitlab.com/") | ||
GIT_POSTFIX = ".git" | ||
REPLACEMENTS = ( | ||
(re.compile(r"^gh:/?(.*\.git)$"), r"https://github.com/\1"), | ||
(re.compile(r"^gh:/?(.*)$"), r"https://github.com/\1.git"), | ||
(re.compile(r"^gl:/?(.*\.git)$"), r"https://gitlab.com/\1"), | ||
(re.compile(r"^gl:/?(.*)$"), r"https://gitlab.com/\1.git"), | ||
) | ||
|
||
|
||
def is_git_repo_root(path: StrOrPath) -> bool: | ||
|
@@ -97,18 +91,13 @@ def get_repo(url: str) -> str | None: | |
url: | ||
Valid examples: | ||
|
||
- gh:copier-org/copier | ||
- gl:copier-org/copier | ||
- [email protected]:copier-org/copier.git | ||
- git+https://mywebsiteisagitrepo.example.com/ | ||
- /local/path/to/git/repo | ||
- /local/path/to/git/bundle/file.bundle | ||
- ~/path/to/git/repo | ||
- ~/path/to/git/repo.bundle | ||
""" | ||
for pattern, replacement in REPLACEMENTS: | ||
url = re.sub(pattern, replacement, url) | ||
|
||
if url.endswith(GIT_POSTFIX) or url.startswith(GIT_PREFIX): | ||
if url.startswith("git+"): | ||
return url[4:] | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,3 +54,72 @@ trust: | |
|
||
Locations ending with `/` will be matched as prefixes, trusting all templates starting with that path. | ||
Locations not ending with `/` will be matched exactly. | ||
|
||
## Shortcuts | ||
|
||
It is possible to define shortcuts in the `shortcuts` setting. It should be a dictionary | ||
where keys are the shortcut names and values are [copier.settings.Shortcut][] objects. | ||
|
||
```yaml | ||
shortcuts: | ||
company: | ||
url: "https://git.company.org" | ||
suffix: true | ||
local: | ||
url: ~/project/templates | ||
suffix: false | ||
``` | ||
|
||
If suffix is `True` (default), the `.git` suffix will be appended to the URL if missing. | ||
|
||
A string can be used as short syntax instead of a full Shortcut object. | ||
|
||
This snippet is equivalent to the previous one: | ||
|
||
```yaml | ||
shortcuts: | ||
company: "https://git.company.org" | ||
local: | ||
url: ~/project/templates | ||
suffix: false | ||
``` | ||
|
||
You can now write: | ||
|
||
```shell | ||
copier copy company:team/repo | ||
copier copy local:template | ||
``` | ||
|
||
There are 2 default shortcuts always available unless you explicitely override them: | ||
|
||
```yaml | ||
shortcuts: | ||
gh: "https://github.com/" | ||
gl: "https://gitlab.com/" | ||
``` | ||
|
||
!!! tip "Working with private repositories" | ||
|
||
If you work with private GitHub or Gitlab repositories, | ||
you might want to override those to force authenticated ssh access: | ||
|
||
```yaml | ||
shortcuts: | ||
gh: '[email protected]:' | ||
gl: '[email protected]:' | ||
``` | ||
|
||
Note the trailing `:` in the URL, it is required to make Git use the SSH protocol. | ||
(`gh:user/repo` will be expanded into `[email protected]:user/repo.git`) | ||
|
||
!!! tip "Trusted locations and shortcuts" | ||
|
||
Trusted locations can be defined using shortcuts. | ||
|
||
```yaml | ||
noirbizarre marked this conversation as resolved.
Show resolved
Hide resolved
|
||
trust: | ||
- gh:user/repo | ||
- gh:company/ | ||
- 'local:' | ||
``` |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.