On Sun, Jun 19, 2011 at 07:21:49PM +0200, Guido Günther wrote: > Patch looks great. But according to the got-clone manpage git also > supports ~user expansion: > > ssh://[user@]host.xz[:port]/~[user]/path/to/repo.git/ > > Could you handle that case too?
Sure. I've attached an updated patch that handles both forms of homedir URLs. This one is a little bit more involved, since I had to modify the remote script, in addition to the URL parsing. (Note that, according to the bash manpage, the "~username/" part can't be quoted, and from testing, dash has the same behavior.)
diff --git a/gbp-create-remote-repo b/gbp-create-remote-repo index e7cce9b..44f3d93 100755 --- a/gbp-create-remote-repo +++ b/gbp-create-remote-repo @@ -26,6 +26,7 @@ import os, os.path import urlparse import subprocess import tty, termios +import re import gbp.deb as du from gbp.command_wrappers import (CommandExecFailed, PristineTar, GitCommand, GitFetch) @@ -55,9 +56,19 @@ def parse_remote(remote_url, name, pkg): raise GbpError, "Remote URL must use ssh protocol." if not '%(pkg)s' in remote_url and not remote_url.endswith(".git"): raise GbpError, "Remote URL needs to contain either a repository name or '%(pkg)s'" + if frags.path.startswith("/~"): + m = re.match(r"/(~[^/]*/)(.*)", frags.path) + if not m: + raise GbpError, "Remote URL contains invalid ~username expansion." + base = m.group(1) + path = m.group(2) + else: + base = "" + path = frags.path remote = { 'pkg' : pkg, 'url' : remote_url % { 'pkg': pkg }, - 'dir' : frags.path % { 'pkg': pkg }, + 'dir' : path % { 'pkg': pkg }, + 'base': base, 'host': frags.netloc, 'name': name} return remote @@ -155,12 +166,12 @@ def main(argv): cat <<EOF set -e umask 002 -if [ -d "%(dir)s" ]; then - echo "Repository at \"%(dir)s\" already exists - giving up." +if [ -d %(base)s"%(dir)s" ]; then + echo "Repository at \"%(base)s%(dir)s\" already exists - giving up." exit 1 fi -mkdir -p "%(dir)s" -cd "%(dir)s" +mkdir -p %(base)s"%(dir)s" +cd %(base)s"%(dir)s" git init --bare --shared echo "%(pkg)s packaging" > description EOF""" % remote