Implement clone subcommand
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Tue, 15 Jan 2013 11:24:11 +0000 (13:24 +0200)
committerMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Thu, 17 Jan 2013 07:36:48 +0000 (09:36 +0200)
For cloning a git repository representing a package managed with gbs.

Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
gitbuildsys/cmd_clone.py [new file with mode: 0644]
tools/gbs

diff --git a/gitbuildsys/cmd_clone.py b/gitbuildsys/cmd_clone.py
new file mode 100644 (file)
index 0000000..1a45ff5
--- /dev/null
@@ -0,0 +1,64 @@
+#!/usr/bin/python -tt
+# vim: ai ts=4 sts=4 et sw=4
+#
+# Copyright (c) 2013 Intel, Inc.
+#
+# 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; version 2 of the License
+#
+# 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.
+
+"""Implementation of subcmd: clone
+"""
+
+from gitbuildsys.conf import configmgr
+from gitbuildsys.errors import GbsError
+from gitbuildsys.log import LOGGER as log
+from gitbuildsys.log import waiting
+
+from gbp.scripts.clone import main as gbp_clone
+
+
+@waiting
+def do_clone(*args, **kwargs):
+    """Wrapper for gbp-clone, prints a progress indicator"""
+    return gbp_clone(*args, **kwargs)
+
+def main(args):
+    """gbs export entry point."""
+
+    # Determine upstream branch
+    if args.upstream_branch:
+        upstream_branch = args.upstream_branch
+    else:
+        upstream_branch = configmgr.get('upstream_branch', 'general')
+
+    # Construct GBP cmdline arguments
+    gbp_args = ['dummy argv[0]',
+                '--color-scheme=magenta:green:yellow:red',
+                '--pristine-tar',
+                '--upstream-branch=%s' % upstream_branch,
+                '--packaging-branch=master']
+    if args.all:
+        gbp_args.append('--all')
+    if args.depth:
+        gbp_args.append('--depth=%s' % args.depth)
+    if args.debug:
+        gbp_args.append("--verbose")
+    gbp_args.append(args.uri)
+
+    # Clone
+    log.info('cloning %s' % args.uri)
+    if do_clone(gbp_args):
+        raise GbsError('Failed to clone %s' % args.uri)
+
+    log.info('finished')
+
index 37ab624ee4ac8a67888d3bd8ce6ccdeb832abe58..3571df42d85779e25e9138cfb5d14c5dbc910925 100755 (executable)
--- a/tools/gbs
+++ b/tools/gbs
@@ -379,6 +379,24 @@ def submit_parser(parser):
     parser.set_defaults(alias="sr")
     return parser
 
+@subparser
+def clone_parser(parser):
+    """Clone a git repository
+    Examples:
+      $ gbs clone git://example.com/repos/package.git
+      $ gbs clone --upstream-branch=orig ../package.git
+    """
+
+    parser.add_argument('uri', help='path/uri to a git repository')
+    parser.add_argument('--upstream-branch', default='upstream',
+                        help='upstream branch')
+    parser.add_argument('--all', action='store_true',
+                        help='track all remote branches')
+    parser.add_argument('--depth',
+                        help='git history depth, for creating shallow clones')
+    parser.set_defaults(alias="cl")
+    return parser
+
 def main(argv):
     """Script entry point."""