diff -Nru git-spindle-2.4/bin/git-bb git-spindle-2.5/bin/git-bb --- git-spindle-2.4/bin/git-bb 2015-04-07 08:02:30.000000000 +0000 +++ git-spindle-2.5/bin/git-bb 2015-04-29 16:58:53.000000000 +0000 @@ -1,5 +1,11 @@ #!/usr/bin/env python +import sys,os +top = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +if os.path.exists(os.path.join(top, '.git')) and os.path.exists(os.path.join(top, 'lib', 'gitspindle')): + # We're in our own git checkout + sys.path.insert(0,os.path.join(top, 'lib')) + from gitspindle.bitbucket import BitBucket BitBucket.prog = 'git bb' diff -Nru git-spindle-2.4/bin/git-bucket git-spindle-2.5/bin/git-bucket --- git-spindle-2.4/bin/git-bucket 2015-04-07 08:02:30.000000000 +0000 +++ git-spindle-2.5/bin/git-bucket 2015-04-29 16:58:53.000000000 +0000 @@ -1,5 +1,11 @@ #!/usr/bin/env python +import sys,os +top = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +if os.path.exists(os.path.join(top, '.git')) and os.path.exists(os.path.join(top, 'lib', 'gitspindle')): + # We're in our own git checkout + sys.path.insert(0,os.path.join(top, 'lib')) + from gitspindle.bitbucket import BitBucket BitBucket().main() diff -Nru git-spindle-2.4/bin/git-hub git-spindle-2.5/bin/git-hub --- git-spindle-2.4/bin/git-hub 2015-04-07 08:02:30.000000000 +0000 +++ git-spindle-2.5/bin/git-hub 2015-04-29 16:58:53.000000000 +0000 @@ -1,5 +1,11 @@ #!/usr/bin/env python +import sys,os +top = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +if os.path.exists(os.path.join(top, '.git')) and os.path.exists(os.path.join(top, 'lib', 'gitspindle')): + # We're in our own git checkout + sys.path.insert(0,os.path.join(top, 'lib')) + from gitspindle.github import GitHub GitHub().main() diff -Nru git-spindle-2.4/bin/git-lab git-spindle-2.5/bin/git-lab --- git-spindle-2.4/bin/git-lab 2015-04-07 08:02:30.000000000 +0000 +++ git-spindle-2.5/bin/git-lab 2015-04-29 16:58:53.000000000 +0000 @@ -1,5 +1,11 @@ #!/usr/bin/env python +import sys,os +top = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +if os.path.exists(os.path.join(top, '.git')) and os.path.exists(os.path.join(top, 'lib', 'gitspindle')): + # We're in our own git checkout + sys.path.insert(0,os.path.join(top, 'lib')) + from gitspindle.gitlab import GitLab GitLab().main() diff -Nru git-spindle-2.4/debian/changelog git-spindle-2.5/debian/changelog --- git-spindle-2.4/debian/changelog 2015-04-29 17:01:17.000000000 +0000 +++ git-spindle-2.5/debian/changelog 2015-04-29 17:01:17.000000000 +0000 @@ -1,4 +1,10 @@ -git-spindle (2.4-1~vivid) vivid; urgency=medium +git-spindle (2.5-1~vivid) vivid; urgency=medium + + * New upstream release + + -- Dennis Kaarsemaker Wed, 29 Apr 2015 18:51:42 +0200 + +git-spindle (2.4-1) utopic; urgency=medium * New upstream release diff -Nru git-spindle-2.4/docs/conf.py git-spindle-2.5/docs/conf.py --- git-spindle-2.4/docs/conf.py 2015-04-07 08:02:30.000000000 +0000 +++ git-spindle-2.5/docs/conf.py 2015-04-29 16:58:53.000000000 +0000 @@ -5,8 +5,8 @@ master_doc = 'index' project = u'git-spindle' copyright = u'2012-2015, Dennis Kaarsemaker' -version = '2.4' -release = '2.4' +version = '2.5' +release = '2.5' exclude_patterns = ['_build'] pygments_style = 'sphinx' html_theme = 'cloud' diff -Nru git-spindle-2.4/lib/gitspindle/bitbucket.py git-spindle-2.5/lib/gitspindle/bitbucket.py --- git-spindle-2.4/lib/gitspindle/bitbucket.py 2015-04-07 08:02:30.000000000 +0000 +++ git-spindle-2.5/lib/gitspindle/bitbucket.py 2015-04-29 16:58:53.000000000 +0000 @@ -30,7 +30,7 @@ except: err("Authentication failed") self.config('password', password) - print("Your BitBucket authentication password is now cached in ~/.gitspindle - do not share this file") + print("Your BitBucket authentication password is now cached in %s - do not share this file" % self.config_file) self.bb = bbapi.Bitbucket(user, password) self.me = self.bb.user(user) @@ -196,7 +196,11 @@ pass self.me.create_repository(slug=name, description=opts['-d'], is_private=opts['--private']) - self.set_origin(opts) + if 'origin' in self.remotes(): + print("Remote 'origin' already exists, adding the BitBucket repository as 'bitbucket'") + self.set_origin(opts, 'bitbucket') + else: + self.set_origin(opts) @command def fork(self, opts): @@ -472,7 +476,7 @@ print(wrap(fmt % (repo.name, '(%s)' % repo.scm, repo.description), *color)) @command - def set_origin(self, opts): + def set_origin(self, opts, remote='origin'): """[--ssh|--http] Set the remote 'origin' to github. If this is a fork, set the remote 'upstream' to the parent""" @@ -485,11 +489,10 @@ pass url = self.clone_url(repo, opts) - if self.git('config', 'remote.origin.url').stdout.strip() != url: - print("Pointing origin to %s" % url) - self.gitm('config', 'remote.origin.url', url) - self.gitm('fetch', 'origin', redirect=False) - self.gitm('config', '--replace-all', 'remote.origin.fetch', '+refs/heads/*:refs/remotes/origin/*') + if self.git('config', 'remote.%s.url' % remote).stdout.strip() != url: + print("Pointing %s to %s" % (remote, url)) + self.gitm('config', 'remote.%s.url' % remote, url) + self.gitm('config', '--replace-all', 'remote.%s.fetch' % remote, '+refs/heads/*:refs/remotes/origin/*') if repo.is_fork: parent = self.bb.repository(repo.fork_of['owner'], repo.fork_of['slug']) @@ -499,6 +502,14 @@ self.gitm('config', 'remote.upstream.url', url) self.gitm('config', 'remote.upstream.fetch', '+refs/heads/*:refs/remotes/upstream/*') + if self.git('ls-remote', remote).stdout.strip(): + self.gitm('fetch', remote, redirect=False) + if repo.is_fork: + self.gitm('fetch', 'upstream', redirect=False) + + if remote != 'origin': + return + for branch in self.git('for-each-ref', 'refs/heads/**').stdout.strip().splitlines(): branch = branch.split(None, 2)[-1][11:] if self.git('for-each-ref', 'refs/remotes/origin/%s' % branch).stdout.strip(): diff -Nru git-spindle-2.4/lib/gitspindle/github.py git-spindle-2.5/lib/gitspindle/github.py --- git-spindle-2.4/lib/gitspindle/github.py 2015-04-07 08:02:30.000000000 +0000 +++ git-spindle-2.5/lib/gitspindle/github.py 2015-04-29 16:58:53.000000000 +0000 @@ -25,7 +25,7 @@ def login(self): host = self.config('host') if host and host not in ('https://api.github.com', 'api.github.com'): - if not hosts.startswith(('http://', 'https://')): + if not host.startswith(('http://', 'https://')): host = 'https://' + host self.gh = github3.GitHubEnterprise(url=host) else: @@ -60,7 +60,7 @@ token = auth.token self.config('token', token) self.config('auth_id', auth.id) - print("A GitHub authentication token is now cached in ~/.gitspindle - do not share this file") + print("A GitHub authentication token is now cached in %s - do not share this file" % self.config_file) print("To revoke access, visit https://github.com/settings/applications") if not user or not token: @@ -328,7 +328,6 @@ if repo.fork: os.chdir(dir) self.set_origin(opts) - self.gitm('fetch', 'upstream', redirect=False) @command def create(self, opts): @@ -339,7 +338,11 @@ if name in [x.name for x in self.gh.iter_repos()]: err("Repository already exists") self.gh.create_repo(name=name, description=opts[''] or "", private=opts['--private']) - self.set_origin(opts) + if 'origin' in self.remotes(): + print("Remote 'origin' already exists, adding the GitHub repository as 'github'") + self.set_origin(opts, 'github') + else: + self.set_origin(opts) @command def edit_hook(self, opts): @@ -963,7 +966,7 @@ os.chmod(goblet_dir, 0o777) @command - def set_origin(self, opts): + def set_origin(self, opts, remote='origin'): """[--ssh|--http|--git] Set the remote 'origin' to github. If this is a fork, set the remote 'upstream' to the parent""" @@ -975,11 +978,10 @@ repo = my_repo url = self.clone_url(repo, opts) - if self.git('config', 'remote.origin.url').stdout.strip() != url: - print("Pointing origin to %s" % url) - self.gitm('config', 'remote.origin.url', url) - self.gitm('fetch', 'origin', redirect=False) - self.gitm('config', '--replace-all', 'remote.origin.fetch', '+refs/heads/*:refs/remotes/origin/*') + if self.git('config', 'remote.%s.url' % remote).stdout.strip() != url: + print("Pointing %s to %s" % (remote, url)) + self.gitm('config', 'remote.%s.url' % remote, url) + self.gitm('config', '--replace-all', 'remote.%s.fetch' % remote, '+refs/heads/*:refs/remotes/%s/*' % remote) if repo.fork: parent = repo.parent @@ -995,7 +997,15 @@ except github3.GitHubError: pass else: - self.gitm('config', '--add', 'remote.origin.fetch', '+refs/pull/*/head:refs/pull/*/head') + self.gitm('config', '--add', 'remote.%s.fetch' % remote, '+refs/pull/*/head:refs/pull/*/head') + + if self.git('ls-remote', remote).stdout.strip(): + self.gitm('fetch', remote, redirect=False) + if repo.fork: + self.gitm('fetch', 'upstream', redirect=False) + + if remote != 'origin': + return for branch in self.git('for-each-ref', 'refs/heads/**').stdout.strip().splitlines(): branch = branch.split(None, 2)[-1][11:] diff -Nru git-spindle-2.4/lib/gitspindle/gitlab.py git-spindle-2.5/lib/gitspindle/gitlab.py --- git-spindle-2.4/lib/gitspindle/gitlab.py 2015-04-07 08:02:30.000000000 +0000 +++ git-spindle-2.5/lib/gitspindle/gitlab.py 2015-04-29 16:58:53.000000000 +0000 @@ -23,6 +23,7 @@ host = self.config('host') or 'https://gitlab.com' if not host.startswith(('http://', 'https://')): host = 'https://' + host + self.host = host user = self.config('user') if not user: @@ -36,7 +37,7 @@ self.gl.auth() token = self.gl.user.private_token self.config('token', token) - print("Your GitLab authentication token is now cached in ~/.gitspindle - do not share this file") + print("Your GitLab authentication token is now cached in %s - do not share this file" % self.config_file) if not user or not token: err("No user or token specified") @@ -103,7 +104,7 @@ pass def profile_url(self, user): - return 'https://gitlab.com/u/%s' % user.username + return '%s/u/%s' % (self.host, user.username) def issue_url(self, issue): repo = self.gl.Project(issue.project_id) @@ -240,7 +241,6 @@ if hasattr(repo, 'forked_from_project'): os.chdir(dir) self.set_origin(opts) - self.gitm('fetch', 'upstream', redirect=False) @command def create(self, opts): @@ -256,7 +256,11 @@ elif opts['--private']: visibility_level = 10 glapi.Project(self.gl, {'name': name, 'description': opts[''] or "", 'visibility_level': visibility_level}).save() - self.set_origin(opts) + if 'origin' in self.remotes(): + print("Remote 'origin' already exists, adding the GitLab repository as 'gitlab'") + self.set_origin(opts, 'gitlab') + else: + self.set_origin(opts) @command def fork(self, opts): @@ -564,7 +568,7 @@ print(msg) @command - def set_origin(self, opts): + def set_origin(self, opts, remote='origin'): """[--ssh|--http] Set the remote 'origin' to gitlab. If this is a fork, set the remote 'upstream' to the parent""" @@ -576,11 +580,11 @@ repo = my_repo url = self.clone_url(repo, opts) - if self.git('config', 'remote.origin.url').stdout.strip() != url: - print("Pointing origin to %s" % url) - self.gitm('config', 'remote.origin.url', url) - self.gitm('config', 'remote.origin.gitlab-id', repo.id) - self.gitm('fetch', 'origin', redirect=False) + if self.git('config', 'remote.%s.url' % remote).stdout.strip() != url: + print("Pointing %s to %s" % (remote, url)) + self.gitm('config', 'remote.%s.url' % remote, url) + self.gitm('config', 'remote.%s.gitlab-id' % remote, repo.id) + self.gitm('config', '--replace-all', 'remote.%s.fetch' % remote, '+refs/heads/*:refs/remotes/%s/*' % remote) parent = self.parent_repo(repo) if parent: @@ -591,6 +595,14 @@ self.gitm('config', 'remote.upstream.gitlab-id', parent.id) self.gitm('config', 'remote.upstream.fetch', '+refs/heads/*:refs/remotes/upstream/*') + if self.git('ls-remote', remote).stdout.strip(): + self.gitm('fetch', remote, redirect=False) + if parent: + self.gitm('fetch', 'upstream', redirect=False) + + if remote != 'origin': + return + for branch in self.git('for-each-ref', 'refs/heads/**').stdout.strip().splitlines(): branch = branch.split(None, 2)[-1][11:] if self.git('for-each-ref', 'refs/remotes/origin/%s' % branch).stdout.strip(): @@ -635,7 +647,7 @@ print('Bio %s' % user.bio) try: for pkey in user.Key(): - algo, key = pkey.key.split() + algo, key = pkey.key.split()[:2] algo = algo[4:].upper() if pkey.title: print("%s key%s...%s (%s)" % (algo, ' ' * (6 - len(algo)), key[-10:], pkey.title)) diff -Nru git-spindle-2.4/lib/gitspindle/__init__.py git-spindle-2.5/lib/gitspindle/__init__.py --- git-spindle-2.4/lib/gitspindle/__init__.py 2015-04-07 08:02:30.000000000 +0000 +++ git-spindle-2.5/lib/gitspindle/__init__.py 2015-04-29 16:58:53.000000000 +0000 @@ -33,6 +33,10 @@ def command(fnc): fnc.is_command = True + if not hasattr(fnc, 'no_login'): + fnc.no_login = False + if not hasattr(fnc, 'wants_parent'): + fnc.wants_parent = False return fnc hidden_command = lambda fnc: os.getenv('DEBUG') and command(fnc) @@ -40,6 +44,10 @@ fnc.wants_parent = True return fnc +def no_login(fnc): + fnc.no_login = True + return fnc + class GitSpindle(object): def __init__(self): @@ -122,6 +130,15 @@ return [None, None, None] return [url.hostname] + self.parse_url(url) + def remotes(self): + confremotes = self.git('config', '--get-regexp', 'remote\..*\.url').stdout.strip().splitlines() + ret = {} + for remote in confremotes: + remote, url = remote.split() + remote = remote.split('.')[1] + ret[remote] = url + return ret + def repository(self, opts, hostname_only=False): # How do we select a repo? # - Did we request one with --repo? @@ -131,7 +148,7 @@ # - Is it mine? Yes -> return it('s parent), No -> remember it # - Return the first rememered one(s parent) # FIXME: errors should mention account if available - remote = None + remote = host = None if opts['']: host, user, repo = self._parse_url(opts['']) if not repo: @@ -201,13 +218,15 @@ hosts = self.git('config', '--file', self.config_file, '--get-regexp', '%s.*host' % self.spindle).stdout.strip() for (account, host) in [x.split() for x in hosts.splitlines()]: - account = account.split('.')[1] + account = account.split('.') if host.startswith(('http://', 'https://')): host = urlparse.urlparse(host).hostname - if self.account == account: + if len(account) == 2: # User has set a host for the default account + self.hosts = [host] + if self.account == account[1]: self.hosts = [host] break - self.accounts[host] = account + self.accounts[host] = account[1] self.hosts.append(host) if not self.account and (self.in_repo or opts['']): @@ -220,7 +239,7 @@ for command, func in self.commands.items(): if opts[command]: - if command != 'add-account': + if not func.no_login: self.login() opts['command'] = command if isinstance(opts[command], list): @@ -228,7 +247,7 @@ opts[command] = True else: opts['extra-opts'] = [] - opts['--maybe-parent'] = getattr(func, 'wants_parent', False) + opts['--maybe-parent'] = func.wants_parent try: func(opts) except KeyboardInterrupt: @@ -236,6 +255,7 @@ break @command + @no_login def add_account(self, opts): """[--host=] Add an account to the configuration""" @@ -245,6 +265,7 @@ self.login() @command + @no_login def config_(self, opts): """[--unset] [] Configure git-spindle, similar to git-config""" diff -Nru git-spindle-2.4/lib/gitspindle/monkey.py git-spindle-2.5/lib/gitspindle/monkey.py --- git-spindle-2.4/lib/gitspindle/monkey.py 2015-04-07 08:02:30.000000000 +0000 +++ git-spindle-2.5/lib/gitspindle/monkey.py 2015-04-29 16:58:53.000000000 +0000 @@ -50,7 +50,7 @@ '--mirror', '--reference=', '--progress', '-o ', '--origin=', '-b ', '--branch=', '-u ', '--upload-pack=', '--template=', '-c ', '--config=', - '--depth', '--single-branch', '--no-single-branch', '--recursive, --recurse-submodules', + '--depth=', '--single-branch', '--no-single-branch', '--recursive, --recurse-submodules', '--separate-git-dir='), } diff -Nru git-spindle-2.4/PKG-INFO git-spindle-2.5/PKG-INFO --- git-spindle-2.4/PKG-INFO 2015-04-07 08:02:31.000000000 +0000 +++ git-spindle-2.5/PKG-INFO 2015-04-29 16:58:54.000000000 +0000 @@ -1,6 +1,6 @@ Metadata-Version: 1.1 Name: git-spindle -Version: 2.4 +Version: 2.5 Summary: Git subcommands for integrating with central services like github, gitlab and bitbucket Home-page: http://github.com/seveas/git-spindle Author: Dennis Kaarsemaker diff -Nru git-spindle-2.4/setup.py git-spindle-2.5/setup.py --- git-spindle-2.4/setup.py 2015-04-07 08:02:30.000000000 +0000 +++ git-spindle-2.5/setup.py 2015-04-29 16:58:53.000000000 +0000 @@ -1,7 +1,7 @@ from distutils.core import setup setup(name='git-spindle', - version="2.4", + version="2.5", description='Git subcommands for integrating with central services like github, gitlab and bitbucket', author='Dennis Kaarsemaker', author_email='dennis@kaarsemaker.net',