git-toggle

Toggle Git remotes between https and ssh.

Docs

Documentation Build Status Docs Check Status

Tests

Linux Test Status Windows Test Status macOS Test Status Coverage

PyPI

PyPI - Package Version PyPI - Supported Python Versions PyPI - Supported Implementations PyPI - Wheel

Activity

GitHub last commit GitHub commits since tagged version Maintenance PyPI - Downloads

QA

CodeFactor Grade Flake8 Status mypy status pre-commit.ci status

Other

License GitHub top language Requirements Status

Installation

python3 -m pip install git-toggle --user

API Reference

Toggle Git remotes between https and ssh.

Classes:

Remote(style, domain, repo, username)

Represents a remote repository.

Toggler(repo, *args, **kwargs)

Toggle Git remotes between https and ssh.

class Remote(style, domain, repo, username)[source]

Bases: object

Represents a remote repository.

Parameters
  • style (str) – The style of remote.

  • domain (str) – The domain of the remote.

  • repo (str) – The repository the remote points to.

  • username (str) – The account on the remote server which owns the repository.

Methods:

as_url()

Returns the apeye.url.URL representation of the :class;`~.Remote`.

from_url(url)

Construct a Remote from a url.

set_repo(repo)

If repo is not None, set repo to that value.

set_username(username)

If username is not None, set username to that value.

Attributes:

domain

The domain of the remote.

repo

The repository the remote points to.

style

The style of remote.

username

The account on the remote server which owns the repository.

as_url()[source]

Returns the apeye.url.URL representation of the :class;`~.Remote`.

Return type

URL

Returns

domain

Type:    str

The domain of the remote.

classmethod from_url(url)[source]

Construct a Remote from a url.

Parameters

url (Union[str, URL])

Return type

Remote

repo

Type:    str

The repository the remote points to.

set_repo(repo)[source]

If repo is not None, set repo to that value.

Parameters

repo (Optional[str])

Returns

The new value of repo`

set_username(username)[source]

If username is not None, set username to that value.

Parameters

username (Optional[str])

Returns

The new value of username`

style

Type:    Literal['https', 'ssh']

The style of remote.

username

Type:    str

The account on the remote server which owns the repository.

class Toggler(repo, *args, **kwargs)[source]

Bases: Repo

Toggle Git remotes between https and ssh.

Parameters

repo (Union[Repo, str, Path, PathLike]) – The repository to toggle remotes for.

Methods:

get_current_remote([name])

Return the current remote.

set_current_remote(url[, name])

Set the current remote.

get_current_remote(name='origin')[source]

Return the current remote.

Parameters

name (str) – If given, try to retrieve the remote with that name. If no such remote exists returns the origin remote. Default 'origin'.

If no remote can be found an empty string will be returned.

Return type

str

set_current_remote(url, name='origin')[source]

Set the current remote.

Parameters
  • url (Union[str, URL, Remote]) – The URL to set for the remote.

  • name (str) – The name of the remote to set. Default 'origin'.

Overview

git-toggle uses tox to automate testing and packaging, and pre-commit to maintain code quality.

Install pre-commit with pip and install the git hook:

python -m pip install pre-commit
pre-commit install

Coding style

formate is used for code formatting.

It can be run manually via pre-commit:

pre-commit run formate -a

Or, to run the complete autoformatting suite:

pre-commit run -a

Automated tests

Tests are run with tox and pytest. To run tests for a specific Python version, such as Python 3.6:

tox -e py36

To run tests for all Python versions, simply run:

tox

Type Annotations

Type annotations are checked using mypy. Run mypy using tox:

tox -e mypy

Build documentation locally

The documentation is powered by Sphinx. A local copy of the documentation can be built with tox:

tox -e docs

Downloading source code

The git-toggle source code is available on GitHub, and can be accessed from the following URL: https://github.com/domdfcoding/git-toggle

If you have git installed, you can clone the repository with the following command:

$ git clone https://github.com/domdfcoding/git-toggle"
> Cloning into 'git-toggle'...
> remote: Enumerating objects: 47, done.
> remote: Counting objects: 100% (47/47), done.
> remote: Compressing objects: 100% (41/41), done.
> remote: Total 173 (delta 16), reused 17 (delta 6), pack-reused 126
> Receiving objects: 100% (173/173), 126.56 KiB | 678.00 KiB/s, done.
> Resolving deltas: 100% (66/66), done.
Alternatively, the code can be downloaded in a ‘zip’ file by clicking:
Clone or download –> Download Zip
Downloading a 'zip' file of the source code.

Downloading a ‘zip’ file of the source code

Building from source

The recommended way to build git-toggle is to use tox:

tox -e build

The source and wheel distributions will be in the directory dist.

If you wish, you may also use pep517.build or another PEP 517-compatible build tool.

View the Function Index or browse the Source Code.

Browse the GitHub Repository