Package gbp :: Package scripts :: Module create_remote_repo

[hide private]
[frames] | no frames]

# Module create_remote_repo

Create a remote Git repository based on the current one

Functions | [hide private]

print_config(remote, branches) Print out the git config to push to the newly created repo. |

sort_dict(d) Return a sorted list of (key, value) tuples |

parse_url(remote_url, name, pkg, template_dir=None) Sanity check our remote URL |

build_remote_script(remote, branch)
Create the script that will be run on the remote side >>> build_remote_script({'base': 'base', 'dir': 'dir', 'pkg': 'pkg', 'template-dir': None}, 'branch') '\nset -e\numask 002\nif [ -d base"dir" ]; then\n echo "Repository at "basedir" already exists - giving up."\n exit 1\nfi\nmkdir -p base"dir"\ncd base"dir"\ngit init --bare --shared\necho "pkg packaging" > description\necho "ref: refs/heads/branch" > HEAD\n' >>> build_remote_script({'base': 'base', 'dir': 'dir', 'pkg': 'pkg', 'template-dir': '/doesnot/exist'}, 'branch') '\nset -e\numask 002\nif [ -d base"dir" ]; then\n echo "Repository at "basedir" already exists - giving up."\n exit 1\nfi\nmkdir -p base"dir"\ncd base"dir"\ngit init --bare --shared --template=/doesnot/exist\necho "pkg packaging" > description\necho "ref: refs/heads/branch" > HEAD\n'

build_cmd(remote) Build the command we pass the script to |

read_yn() |

setup_branch_tracking(repo, remote, branches) |

push_branches(remote, branches) |

build_parser(name, sections=`[``]`) |

parse_args(argv, sections=`[``]`) Parse the command line arguments and config files. |

main(argv) |

Variables | [hide private]

| __package__ = ``'``gbp.scripts``'``

Function Details | [hide private]

### print_config(remote, branches)

Print out the git config to push to the newly created repo.

    >>> print_config({'name': 'name', 'url': 'url'}, ['foo', 'bar'])
    [remote "name"]
            url = url
            fetch = +refs/heads/*:refs/remotes/name/*
            push = foo
            push = bar
    [branch "foo"]
            remote = name
            merge = refs/heads/foo
    [branch "bar"]
            remote = name
            merge = refs/heads/bar

### parse_url(remote_url, name, pkg, template_dir=None)

Sanity check our remote URL

    >>> sort_dict(parse_url("ssh://host/path/%(pkg)s", "origin", "package"))
    [('base', ''), ('dir', '/path/package'), ('host', 'host'), ('name', 'origin'), ('pkg', 'package'), ('port', None), ('scheme', 'ssh'), ('template-dir', None), ('url', 'ssh://host/path/package')]

    >>> sort_dict(parse_url("ssh://host:22/path/repo.git", "origin", "package"))
    [('base', ''), ('dir', '/path/repo.git'), ('host', 'host'), ('name', 'origin'), ('pkg', 'package'), ('port', '22'), ('scheme', 'ssh'), ('template-dir', None), ('url', 'ssh://host:22/path/repo.git')]

    >>> sort_dict(parse_url("ssh://host:22/~/path/%(pkg)s.git", "origin", "package"))
    [('base', '~/'), ('dir', 'path/package.git'), ('host', 'host'), ('name', 'origin'), ('pkg', 'package'), ('port', '22'), ('scheme', 'ssh'), ('template-dir', None), ('url', 'ssh://host:22/~/path/package.git')]

    >>> sort_dict(parse_url("ssh://host:22/~user/path/%(pkg)s.git", "origin", "package", "/doesnot/exist"))
    [('base', '~user/'), ('dir', 'path/package.git'), ('host', 'host'), ('name', 'origin'), ('pkg', 'package'), ('port', '22'), ('scheme', 'ssh'), ('template-dir', '/doesnot/exist'), ('url', 'ssh://host:22/~user/path/package.git')]

    >>> parse_url("git://host/repo.git", "origin", "package")
    Traceback (most recent call last):
        ...
    GbpError: URL must use ssh protocol.
    >>> parse_url("ssh://host/path/repo", "origin", "package")
    Traceback (most recent call last):
        ...
    GbpError: URL needs to contain either a repository name or '%(pkg)s'
    >>> parse_url("ssh://host:asdf/path/%(pkg)s.git", "origin", "package")
    Traceback (most recent call last):
        ...
    GbpError: URL contains invalid port.
    >>> parse_url("ssh://host/~us er/path/%(pkg)s.git", "origin", "package")
    Traceback (most recent call last):
        ...
    GbpError: URL contains invalid ~username expansion.

### build_cmd(remote)

Build the command we pass the script to

    >>> build_cmd({'scheme': ''})
    ['sh']
    >>> build_cmd({'scheme': 'ssh', 'host': 'host', 'port': 80})
    ['ssh', '-p', 80, 'host', 'sh']

### parse_args(argv, sections=`[``]`)

Parse the command line arguments and config files.

Parameters:
  - `argv` (`list` of `str`) - the command line arguments
  - `sections` (`list` of `str`) - additional sections to add to the config file parser besides the command name