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 reup-tag option to git plugin #234

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ __pycache__
peru.egg-info
build/
dist/
.venv/*
11 changes: 11 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,17 @@ If you are working on a new feature please add tests to ensure the feature works

Tests are stored in `peru/tests` and verify the current implementation to see how your test will fit in.

## Installing Locally

To test your changes, you can install/uninstall the project locally:

```bash
make install
```
```bash
make uninstall
```

## Making a Pull Request

Once you have made your changes and are ready to make a Pull Request please ensure tests and linting pass locally before pushing to GitHub.
Expand Down
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ deps-dev: ## Install development dependencies

##@ Utility

.PHONY: install
install: ## Install peru
$(PYTHON) setup.py install --user

.PHONY: uninstall
uninstall: ## Uninstall peru
$(PIP) uninstall peru

.PHONY: help
help: ## Display this help
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\033[0m\n"} /^[\#a-zA-Z0-9_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ git module vim-solarized:
url: https://github.com/altercation/vim-colors-solarized
# Fetch this exact commit, instead of master or main.
rev: 7a7e5c8818d717084730133ed6b84a3ffc9d0447

git module dracula:
url: https://github.com/dracula/vim
reup-tag: true
rev: v1.5.0
```

The contents of the `dircolors` module are copied to the root of our repo. The
Expand Down Expand Up @@ -186,6 +191,12 @@ index 15c758d..7f0e26b 100644
url: https://github.com/altercation/vim-colors-solarized
- rev: 7a7e5c8818d717084730133ed6b84a3ffc9d0447
+ rev: 528a59f26d12278698bb946f8fb82a63711eec21

git module dracula:
url: https://github.com/dracula/vim
reup-tag: true
- rev: v1.5.0
+ rev: v2.0.0
```

Peru made three changes:
Expand Down Expand Up @@ -231,6 +242,7 @@ For cloning repos. These types all provide the same fields:
- `rev`: optional, the specific revision/branch/tag to fetch
- `reup`: optional, the branch/tag to get the latest rev from when running
`peru reup`
- `reup-tag`: optional, whether to update the rev with the latest tag instead of the latest commit hash when running `peru reup`

The `git` type also supports setting `submodules: false` to skip
fetching git submodules. Otherwise they're included by default.
Expand Down
13 changes: 9 additions & 4 deletions peru/resources/plugins/git/git_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,16 @@ def plugin_sync(url, rev):
checkout_tree(url, rev, os.environ['PERU_SYNC_DEST'])


def plugin_reup(url, reup):
def plugin_reup(url, reup, reup_tag):
reup_output = os.environ['PERU_REUP_OUTPUT']
repo_path = clone_if_needed(url)
git_fetch(url, repo_path)
output = git(
'rev-parse', reup, git_dir=repo_path, capture_output=True).output
if reup_tag:
output = git('describe', '--tags', '--abbrev=0', git_dir=repo_path,
capture_output=True).output
else:
output = git(
'rev-parse', reup, git_dir=repo_path, capture_output=True).output
with open(reup_output, 'w') as out_file:
print('rev:', output.strip(), file=out_file)

Expand Down Expand Up @@ -188,12 +192,13 @@ def main():
default_branch = git_default_branch(URL)
REV = os.environ['PERU_MODULE_REV'] or default_branch
REUP = os.environ['PERU_MODULE_REUP'] or default_branch
REUP_TAG = os.environ['PERU_MODULE_REUP-TAG'] == 'true'

command = os.environ['PERU_PLUGIN_COMMAND']
if command == 'sync':
plugin_sync(URL, REV)
elif command == 'reup':
plugin_reup(URL, REUP)
plugin_reup(URL, REUP, REUP_TAG)
else:
raise RuntimeError('Unknown command: ' + repr(command))

Expand Down
1 change: 1 addition & 0 deletions peru/resources/plugins/git/plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ optional fields:
- rev
- reup
- submodules
- reup-tag
cache fields:
- url