Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Git-Repo: CLI utility to manage git services from your workspace

License

NotificationsYou must be signed in to change notification settings

guyzmo/git-repo

Repository files navigation

Looking for help

For the past few months I've been really busy coding on stuff that puts food on the table…And sadly, I cannot give this project all the love it deserves. Which is why it's taken me monthsto spend a few hours merge and release the PRs featured in this repository.

I'm still using this project daily, but I'm not having enough time to keep on putting all theeffort needed to make it shine (SSH keys, issues support…)

So I'd like to share the maintenance responsibility with someone or more people. If you'reinterested, please ping me on IRC or by mail (which is in all my commits). I'm always happyto guide through the code's design!

Usage

main commands

Control your remote git hosting services from thegit commandline. The usage isvery simple (full usage listin the sources). To clone a new project, out of GitHub, just issue:

% git hub clone guyzmo/git-repo

But that works also with a project from GitLab, Bitbucket, your own GitLab or Gogs:

% git lab clone guyzmo/git-repo% git bb clone guyzmo/git-repo% git myprecious clone guyzmo/git-repo% git gg clone guyzmo/git-repo

If you want to choose the default branch to clone:

% git lab clone guyzmo/git-repo master

Though sometimes, as you're starting a new project, you want to create a newrepository to push to:

% git hub create guyzmo/git-repo

actually the namespace is facultative, as per default you can (and want to)only create new repositories within your own account.

You might also want to add an existing remote ref to your workspace, and thatcan be easily done with:

% git lab add guyzmo/git-repo

Which will addhttps://gitlab.com/guyzmo/git-repo as thegitlab remote!

Also, you can fork a repository using:

% git hub fork neovim/neovim

and of course, you can delete it using:

% git bb delete guyzmo/git-repo

Also, you can open the repository's page, using theopen command:

% git lab open guyzmo/git-repoSuccessfully fetched branch `2` of `guyzmo/git-repo` into `request-2`!

Requests for merges(aka Pull Requests aka Merge Requests)

Once you're all set with your repository, you can check requests to merge(aka Pull Requests on github) using therequest command:

% git hub request guyzmo/git-repo listList of open requests to merge:id     title                                                           URL2     prefer gitrepo.<target>.token > privatekey, docs                https://api.github.com/repos/guyzmo/git-repo/issues/2

And fetch it locally to check and/or amend it before merging:

% git hub request guyzmo/git-repo fetch 2

Or you can create a request by doing a:

% git hub request create guyzmo/git-repo myfeature master -t 'My neat feature' -m 'So much to say about that feature…'

You can create the request also by simply calling:

% git hub request create

That command has a bit of automagic, it will:

  1. lookup the namespace and project of the current branch (or at least on thegithubremote, if called withhub), and take this as the source of the request ;
  2. for the target of the request it will lookup and take:
  • the parent if current project has a parent
  • or itself, if does not ;
  1. it will take the currently loaded branch for the source
  2. and the default one for the target
  3. call the service to ask for a request to merge from source onto target.

Gists or snippets

Finally, another extra feature you can play with is the gist handling:

% git hub gist listid                                                              titlehttps://gist.github.com/4a0dd9177524b2b125e9166640666737        This is a test gist

Then you can list files within it:

% git hub gist list a7ce4fddba7744ddf335language         size  namePython           1048  unicode_combined.py% git hub -v gist list https://gist.github.com/4a0dd9177524b2b125e9166640666737language         size  nameMarkdown         16    README.mdText             14    LICENSEreStructuredText 17    README.rst

to output it locally, you can use the fetch command (and specify the file if there's more than one):

% git hub gist fetch https://gist.github.com/a7ce4fddba7744ddf335 > mygist.py% git hub gist fetch 4a0dd9177524b2b125e9166640666737 LICENSE > LICENSE_from_gist

but for more thorough modifications or consulting, you can as well clone it:

% git hub gist clone 4a0dd9177524b2b125e9166640666737Pulling from github |████████████████████████████████|Successfully cloned `4a0dd9177524b2b125e9166640666737` into `./4a0dd9177524b2b125e9166640666737`!

And when you're done you just get rid of it:

% git hub gist -f delete 4a0dd9177524b2b125e9166640666737Successfully deleted gist!

Nota Bene: Thanks togit CLI flexibility, by installinggit-repo you directlyhave access to the tool usinggit-repo hub … orgit repo hub …. For thegit hub … call, you have to set up aliases, see below how to configure that.

Remotes

Traditionally,origin is being used as the remote name for the code hosted on aservice, but because of the nature ofgit-repo there is no singleorigin butit encourages to use multiple ones, and also leave you in control of whereverorigin points to.

This is why when you clone from a service or create a new repo on a service,it's using a special remote that carries the name of the service:

% git hub clone foo/bar; cd bar% git status -sb | head -1## master...github/master            ^^^^^^% git lab create bar% git push gitlab master

And as a bonus, each time it's adding a new remote, it's updating theall remote,so that you can push your code to all your remote repositories in one command:

% git push all master

Another special remote is theupstream. When you do a fork of a project, currentspecial remote with a service name will be renamed asupstream and the newlyforked project is now the one with the service name:

% git lab clone foo/bar; cd bar% git remoteallgitlab% git lab fork% git remoteallgitlabupstream

Finally, if you want to link other existing projects, you can, theadd commandis there for that:

% git bb add foo/bar% # if the name is identical to current project, you don't need to add a name% git hub add% git gg add foo/bar gitea --alone

Use the--alone switch if you don't want to add that project in theallspecial remote.

And of course the above commands is just sugar around regular git commands,so the above can also be done with:

% git remote add gitbucket https://gitbucket.local:8080/foo/bar% # the command to append the URL to the all remote, --alone skips this step% git remote set-url --add all https://gitbucket.local:8080/foo/bar

And to remove a remote, just do:

% git remote remove github

Installation

You can get the tool using pypi (usepip3 if you have both Python2 and Python3 installed):

% pip install git-repo

or by getting the sources and running:

% python3 setup.py install

Configuration

To configuregit-repo you simply have to call the following command:

% git repo config

and a wizard will run you through getting the authentication token for theservice, add the command alias or the name of the remote. Though, configuringcustom services is still not handled by the wizard…

But if you prefer manual configuration you'll have to tweak your~/.gitconfig. For each service you've got an account on, you have to make asection in the gitconfig:

[gitrepo "gitlab"]    token = YourVerySecretKey[gitrepo "github"]    token = YourOtherVerySecretKey[gitrepo "bitbucket"]    username = ford.prefect    token = YourSecretAppKey[gitrepo "gogs"]    fqdn = UrlOfYourGogs    token = YourVerySecretKey

Here, we're setting the basics: just the private token. Notice that the token needed for Bitbucket are an App-token, not to be confused with an OAuth-token, which are also avaiable from the Butbucket settings.

You also have the ability to set up an alias:

[gitrepo "bitbucket"]    alias = bit    username = ford.prefect    token = YourSecretAppKey

that will change the command you use for a name you'll prefer to handle actionsfor the service you use:

% git-repo bit clone guyzmo/git-repo

Also, you can setup your own GitLab self-hosted server, using that configuration:

[gitrepo "myprecious"]    type = gitlab    token = YourSuperPrivateKey    fqdn = gitlab.example.org    # Set this only if you use a self-signed certificate and experience problems    insecure = true

Finally, to make it really cool, you can make a few aliases in your gitconfig:

[alias]    hub = repo hub    lab = repo lab    bb = repo bb    perso = repo perso

So you can run the tool as a git subcommand:

git hub clone guyzmo/git-repo

For those who like to keep all dotfiles in a git repository, it'd be horrendous tostore tokens that offer access to your social accounts in a repository… And I'm noteven talking about those who want to share your dotfiles. But don't worry, onceit's all configured, you can fire up yourfavorite editor andmove all the[gitrepo …] sections into a new file, like~/.gitconfig-repos.

Your can run the following command to do this automagically:

python -m git_repo.extract_config

if you want to use another path, you can change the defaults:

python -m git_repo.extract_config ~/.gitconfig-repos ~/.gitconfig

Configuring Gerrit

Please note: when configuration wizard will ask you for password, do not provideyour Gerrit account password, but enterHTTP password instead. You can setupit onSettings > HTTP Password page

You may also need to tweak your~/.gitconfig:

  • setro-suffix if your Gerrit isn't served at server root. For example, setro-suffix to/r if your Gerrit is hosted athttps://review.host.com/r
  • setssh-port parameter to set custom port for ssh connection to Gerrit (default: 29418)
  • setauth-type: basic (default) or digest

Development

For development, start a virtualenv and from within install the devel requirements:

% virtualenv var% var/bin/pip install -r requirements-test.txt

and then you'll have the executable inbin:

% var/bin/git-repo --help

and to run the tests:

% var/bin/py.test --cov=git_repo --cov-report term-missing --capture=sys tests

N.B.:Buildout is no longer supported for development

Verbose running

You can repeat the-v argument several times to increase the level of verbosityofgit-repo. The more arguments you give, the more details you'll have.

  • -v will set the debugging level toDEBUG, giving some execution info ;
  • -vv will print out all the git commands that are being executed ;
  • -vvv will give more verbose insight on the git layer ;
  • -vvvv will output all the HTTP exchanges with the different APIs ;
  • -vvvvv will printout how were parsed the arguments.
Testing

To run the tests:

% bin/py.test

You can use the following options for py.test to help you debug when tests fail:

  • -v will show more details upon errors
  • -x will stop upon the first failure
  • --pdb will launch the debugger where an exception has been launched

The tests use recordings of exchanged HTTP data, so that we don't need real credentialsand a real connection, when testing the API on minor changes. Those recordings arecalled cassettes, thanks to thebetamax frameworkbeing in use in the test suites.

When running existing tests, based on the provided cassettes, you don't need anysetting. Also, if you've got a configuration in~/.gitconfig, the tests will usethem. Anyway, you can use environment variables for those settings (environmentvariables will have precedence over the configuration settings):

To use your own credentials, you can setup the following environment variables:

  • GITHUB_NAMESPACE (which defaults tonot_configured) is the name of the account to use on GitHub
  • GITLAB_NAMESPACE (which defaults tonot_configured) is the name of the account to use on GitLab
  • BITBUCKET_NAMESPACE (which defaults tonot_configured) is the name of the account to use on Bitbucket
  • GOGS_NAMESPACE (which defaults tonot_configured) is the name of the account to use on Gogs
  • PRIVATE_KEY_GITHUB your private token you've setup on GitHub for your account
  • PRIVATE_KEY_GITLAB your private token you've setup on GitLab for your account
  • PRIVATE_KEY_BITBUCKET your private token you've setup on Bitbucket for your account
  • PRIVATE_KEY_GOGS your private token you've setup on Gogs for your account

TODO

  • make agit-repo fork action
  • make it possible to choose method (SSH or HTTPS)
  • handle default branches properly
  • make a nice way to push to all remotes at once
  • refactor the code into multiple modules
  • add regression tests (and actually find a smart way to implement them…)
  • add travis build
  • show a nice progress bar, while it's fetching (cf#15)
  • add support for handling gists (cf#12, cf#13)
  • add support for handling pull requests (cf#10,#11)
  • add application token support for bitbucket (cf#14)
  • add support for gogs (cf#18)
  • add support for gitbucket (cf#142)
  • add support for managing SSH keys (cf#22)
  • add support for issues (cf#104)
  • add support for gerrit (cf#19)
  • do what's needed to make a nice documentation#146
  • for more features, write an issue or, even better, a PR!

Contributors

The project and original idea has been brought and is maintained by:

With code contributions coming from:

License

Copyright ©2016,2017 Bernard `Guyzmo` Pratz <guyzmo+git-repo+pub@m0g.net>This program is free software; you can redistribute it and/ormodify it under the terms of the GNU General Public Licenseas published by the Free Software Foundation; either version 2of the License, or (at your option) any later version.This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with this program; if not, write to the Free SoftwareFoundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

See the LICENSE file for the full license.


[8]ページ先頭

©2009-2025 Movatter.jp