Skip to content

Commit

Permalink
Add top-level completion command
Browse files Browse the repository at this point in the history
  • Loading branch information
PawelLipski committed Aug 12, 2023
1 parent 5c5b0dd commit f32225c
Show file tree
Hide file tree
Showing 35 changed files with 882 additions and 405 deletions.
25 changes: 23 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,21 @@ jobs:
name: Install dependencies
# language=sh
command: |
set -x
# For completion tests
# `add-apt-repository` was getting stuck on CI for some reason
echo 'deb https://ppa.launchpadcontent.net/fish-shell/release-3/ubuntu jammy main' | sudo tee -a /etc/apt/sources.list
echo 'deb-src https://ppa.launchpadcontent.net/fish-shell/release-3/ubuntu jammy main' | sudo tee -a /etc/apt/sources.list
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 59FDA1CE1B84B3FAD89366C027557F056DC33CA5
sudo apt-get update
sudo apt-get install fish
fish --version
# For enforce-completion-scripts-correct.sh
sudo apt-get install zsh fish
sudo apt-get install zsh
pip3 install tox
# For enforce-shell-scripts-pass-shellcheck.sh
sudo apt-get install shellcheck
Expand All @@ -43,6 +54,11 @@ jobs:
- run:
name: Perform general checks
command: ci/checks/run-all-checks.sh
- run:
name: Test shell completions
command: tox -e test-completions -- -vv
- store_test_results:
path: test-results/

# Earliest versions of python/git supported by git-machete
"python 3_6 git 1_8_0":
Expand Down Expand Up @@ -146,7 +162,10 @@ jobs:
executor: macos_executor
steps:
- checkout
- run: brew install fish zsh
- run: pip install tox
# TODO (#1005): make zsh completion tests pass on macOS machine on CI
- run: tox -e test-completions -- -vv -k "not zsh"
- run: PYTHON_VERSION=3.11-macos tox -e coverage -- -vv
- store_test_results:
path: test-results/
Expand All @@ -161,6 +180,8 @@ jobs:
- run: pip install tox
# We don't collect coverage on Windows as it massively extends execution time for some reason.
- run: tox -e testenv -- -vv
- store_test_results:
path: test-results/

"coverage upload":
executor: ubuntu_executor
Expand Down
52 changes: 28 additions & 24 deletions PACKAGES.md

Large diffs are not rendered by default.

35 changes: 32 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# git-machete

[![homebrew formula](https://img.shields.io/homebrew/v/git-machete)](https://formulae.brew.sh/formula/git-machete)
[![homebrew formula monthly downloads](https://img.shields.io/homebrew/installs/dm/git-machete.svg)](https://formulae.brew.sh/formula/git-machete)
[![PyPI package](https://img.shields.io/pypi/v/git-machete.svg)](https://pypi.org/project/git-machete)
[![PyPI package monthly downloads](https://img.shields.io/pypi/dm/git-machete.svg)](https://pypistats.org/packages/git-machete)
[![Conda package](https://img.shields.io/conda/vn/conda-forge/git-machete.svg)](https://anaconda.org/conda-forge/git-machete)
Expand Down Expand Up @@ -43,8 +44,6 @@ a port into a plugin for the IntelliJ Platform products, including PyCharm, WebS

We provide a couple of alternative ways of installation. See [PACKAGES.md](PACKAGES.md) for the full list.

**Instructions for installing bash, zsh, and fish completion scripts are provided in [completion/README.md](completion/README.md).**

git-machete requires Python >= 3.6. Python 2.x is no longer supported.

### Using Homebrew (macOS & most Linux distributions)
Expand Down Expand Up @@ -181,8 +180,38 @@ This will be resolved from the first of:
3. Auth token from the current [`gh`](https://cli.github.com/) configuration.
4. Auth token from the current [`hub`](https://github.com/github/hub) configuration.

<br/>
### Shell completions

When git-machete is installed via **Homebrew**, shell completions should be installed automatically. <br/>
For any other package manager, or when your shell doesn't pick up the Homebrew-installed completion, use the following:

#### Bash

Put the following into `~/.bashrc` or `~/.bash_profile`:

```shell script
eval "$(git machete completion bash)" # or, if it doesn't work:
source <(git machete completion bash)
```

#### Fish

Put the following into `~/.config/fish/config.fish`:

```shell script
git machete completion fish | source
```

#### Zsh

Put the following into `~/.zshrc`:

```shell script
eval "$(git machete completion zsh)" # or, if it doesn't work:
source <(git machete completion zsh)
```

<br/>

## FAQ

Expand Down
3 changes: 3 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## New in git-machete 3.18.0

- added: `git machete completion bash|fish|zsh` command
- fixed: multiple glitches in the existing bash/fish/zsh completions

## New in git-machete 3.17.9

- improved: layout of documentation at ReadTheDocs
Expand Down
7 changes: 0 additions & 7 deletions ci/checks/enforce-completion-scripts-correct.sh

This file was deleted.

7 changes: 3 additions & 4 deletions ci/checks/enforce-mocking-only-whitelisted-methods.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ self_dir=$(cd "$(dirname "$0")" &>/dev/null; pwd -P)
source "$self_dir"/utils.sh
self_name=$(basename "$0")

whitelisted_methods='
whitelisted_methods="\
builtins.input
builtins.open
git_machete.client.MacheteClient.is_stdout_a_tty
Expand All @@ -20,9 +20,8 @@ git_machete.utils.find_executable
os.path.isfile
shutil.which
sys.argv
urllib.request.urlopen
'
actual_methods=$(git grep -Pho "(?<=self\.patch_symbol\(mocker, ['\"]).*?(?=['\"])" | sort -u)
urllib.request.urlopen"
actual_methods=$(git grep -Pho "(?<=self\.patch_symbol\(mocker, ['\"]).*?(?=['\"])" | LC_COLLATE=C sort -u)

# `comm -13` to list lines only present in the second input (actual methods) and not in the first (whitelisted methods)
# `grep ''` to check if the output is non-empty (true if non-empty, false if empty)
Expand Down
2 changes: 1 addition & 1 deletion ci/checks/enforce-shell-scripts-pass-shellcheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

set -e -o pipefail -u

{ git grep --name-only '#!.*sh$' -- ':!*.md'; git ls-files '*.sh'; } \
{ git grep --name-only '#!.*sh$' -- ':!*.md' ':!*.fish' ':!*.zsh'; git ls-files '*.sh'; } \
| sort --unique \
| xargs shellcheck --check-sourced --exclude=SC1090,SC1091,SC2016,SC2086,SC2090,SC2125 --severity=info --shell=bash
2 changes: 1 addition & 1 deletion ci/checks/prohibit-bash-usages-from-python.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -e -o pipefail -u

if git grep -n bash -- tests/ '*.py'; then
if git grep -n -e bash --and --not -e compl -- '*.py' ':!git_machete/generated_docs.py' 'tests/' ':!tests/completion_e2e/'; then
echo
echo 'Do not rely on bash being installed, not even in tests.'
echo 'See e.g. https://github.com/VirtusLab/git-machete/pull/929.'
Expand Down
1 change: 0 additions & 1 deletion ci/checks/run-all-checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ PATH=./ci/checks:$PATH
set -e -x

enforce-bumped-version.sh
enforce-completion-scripts-correct.sh
enforce-consistent-style-for-fork-point.sh
enforce-consistent-style-for-github.sh
enforce-correct-shebangs.sh
Expand Down
1 change: 1 addition & 0 deletions ci/deb-ppa-upload/build-context/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ cat ../python3-git-machete_*_source.buildinfo
cat ../python3-git-machete_*_source.changes

tar_output=$(tar tvf ../python3-git-machete_*.tar.gz)
echo "$tar_output"
grep completion/ <<< "$tar_output"
grep docs/man/git-machete\.1 <<< "$tar_output"

Expand Down
5 changes: 5 additions & 0 deletions ci/homebrew/ci-deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,10 @@ else
echo "man page has not been installed, aborting"
exit 1
fi
if ! git machete completion bash | grep '#!.*bash'; then
echo "shell completion is not available in runtime, aborting"
exit 1
fi

brew remove git-machete
fi
4 changes: 4 additions & 0 deletions ci/rpm/build-context/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ fi
python3 setup.py bdist_rpm
rpm -i dist/git-machete-*.rpm
git machete version
if ! git machete completion bash | grep '#!.*bash'; then
echo "shell completion is not available in runtime, aborting"
exit 1
fi
4 changes: 4 additions & 0 deletions ci/snap/ci-deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ if [[ ${1-} == "--dry-run" || ${CIRCLE_BRANCH-} != "master" ]]; then
if command -v git-machete; then exit 1; fi
sudo snap install git-machete*.snap --dangerous --classic
git machete version
if ! git machete completion bash | grep '#!.*bash'; then
echo "shell completion is not available in runtime, aborting"
exit 1
fi
sudo snap remove git-machete
else
# Relying on SNAPCRAFT_STORE_CREDENTIALS, provided by the CI
Expand Down
12 changes: 10 additions & 2 deletions ci/tox/build-context/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,16 @@ $PYTHON -m venv venv/bdist_wheel/

. venv/sdist/bin/activate
pip install dist/git-machete-*.tar.gz
git machete --version
git machete version
if ! git machete completion fish | grep 'complete -c git-machete'; then
echo "shell completion is not available in runtime, aborting"
exit 1
fi

. venv/bdist_wheel/bin/activate
pip install dist/git_machete-*.whl
git machete --version
git machete version
if ! git machete completion zsh | grep '#compdef git-machete'; then
echo "shell completion is not available in runtime, aborting"
exit 1
fi
124 changes: 0 additions & 124 deletions completion/README.md

This file was deleted.

1 change: 1 addition & 0 deletions completion/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# See https://github.com/python/cpython/issues/89838 for why this file is needed
Loading

0 comments on commit f32225c

Please sign in to comment.