aboutsummaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2009-09-05 13:06:41 +0200
committerGuido Günther <agx@sigxcpu.org>2009-09-05 13:44:38 +0200
commit13316be851e143ca21fc0dac011bc02963a0f28c (patch)
treefd0fba6af5c75c55c2803edf500324bd40366668 /examples
parent838b3f4493686c851298ba275156702aa07b1734 (diff)
Add gbp-clone
to examples. Using this to clone repositories will automatically track the remote branches used by gbp. Adresses parts of #540185.
Diffstat (limited to 'examples')
-rwxr-xr-xexamples/gbp-clone95
1 files changed, 95 insertions, 0 deletions
diff --git a/examples/gbp-clone b/examples/gbp-clone
new file mode 100755
index 00000000..12e343f3
--- /dev/null
+++ b/examples/gbp-clone
@@ -0,0 +1,95 @@
+#!/usr/bin/python -u
+# vim: set fileencoding=utf-8 :
+#
+# (C) 2009 Guido Guenther <agx@sigxcpu.org>
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of 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 of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# inspired by dom-git-checkout
+#
+"""clone a repo and set it up for gbp"""
+
+import sys
+import os, os.path
+from gbp.config import (GbpOptionParser, GbpOptionGroup)
+from gbp.git import (GitRepositoryError, GitRepository)
+from gbp.command_wrappers import (GitClone, CommandExecFailed, GitBranch)
+from gbp.errors import GbpError
+
+
+def main(argv):
+ retval = 0
+ pristine_tar_branch = 'pristine-tar'
+
+ parser = GbpOptionParser(command=os.path.basename(argv[0]), prefix='',
+ usage='%prog [options] repository - clone a remote repository')
+ branch_group = GbpOptionGroup(parser, "branch options", "branch layout options")
+ parser.add_option_group(branch_group)
+
+ branch_group.add_config_file_option(option_name="upstream-branch", dest="upstream_branch")
+ branch_group.add_config_file_option(option_name="debian-branch", dest="debian_branch")
+ branch_group.add_boolean_config_file_option(option_name="pristine-tar", dest="pristine_tar")
+ parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False,
+ help="verbose command execution")
+
+ (options, args) = parser.parse_args(argv)
+
+ if len(args) != 2:
+ print >>sys.stderr, "Need a repository to clone.\n"
+ parser.print_help()
+ return 1
+ else:
+ repo = args[1]
+
+ if options.verbose:
+ Command.verbose = True
+
+ try:
+ repo = GitRepository(os.path.curdir)
+ print >>sys.stderr, "Can't run inside a git repository."
+ return 1
+ except GitRepositoryError:
+ pass
+
+
+ branches = [ options.debian_branch, options.upstream_branch ]
+ try:
+ GitClone()([repo])
+
+ (clone, dummy) = os.path.splitext(repo.rsplit('/',1)[1])
+ os.chdir(clone)
+
+ repo = GitRepository(os.path.curdir)
+
+ if options.pristine_tar:
+ branches += [ pristine_tar_branch ]
+
+ for branch in branches:
+ remote = 'origin/%s' % branch
+ if repo.has_branch(remote, remote=True) and \
+ not repo.has_branch(branch):
+ GitBranch()(branch, remote)
+
+ except CommandExecFailed:
+ retval = 1
+ except GbpError, err:
+ if len(err.__str__()):
+ print >>sys.stderr, err
+ retval = 1
+
+ return retval
+
+if __name__ == '__main__':
+ sys.exit(main(sys.argv))
+