[projects/git-slug: 34/170] Add clone subcommand
glen
glen at pld-linux.org
Mon Sep 21 21:41:40 CEST 2015
commit 5eeeb5a4773f9c11dd1d91358438176aad827bcf
Author: Kacper Kornet <draenog at pld-linux.org>
Date: Tue Sep 20 22:30:25 2011 +0100
Add clone subcommand
git_slug/gitrepo.py | 4 ++++
slug.py | 28 +++++++++++++++++++++++-----
2 files changed, 27 insertions(+), 5 deletions(-)
---
diff --git a/git_slug/gitrepo.py b/git_slug/gitrepo.py
index f6cfecb..c874460 100644
--- a/git_slug/gitrepo.py
+++ b/git_slug/gitrepo.py
@@ -33,6 +33,10 @@ class GitRepo:
raise GitRepoError(err.decode('utf-8'))
return (out, err)
+ def checkout(self, branch):
+ clist = ['checkout', '-m', branch]
+ return self.commandexc(clist)
+
def commitfile(self, path, message):
clist = ['commit', '-m', message, path]
self.commandio(clist)
diff --git a/slug.py b/slug.py
index 0ac1d55..3033027 100755
--- a/slug.py
+++ b/slug.py
@@ -103,6 +103,7 @@ def fetch_packages(options):
print('Read remotes data')
+ updated_repos=[]
for dir in sorted(refs.heads):
gitdir = os.path.join(options.packagesdir, dir, '.git')
if not os.path.isdir(gitdir):
@@ -110,6 +111,8 @@ def fetch_packages(options):
gitrepo = initpackage(dir, options)
else:
continue
+ elif options.omitexisting:
+ continue
else:
gitrepo = GitRepo(os.path.join(options.packagesdir, dir))
ref2fetch = []
@@ -118,6 +121,7 @@ def fetch_packages(options):
ref2fetch.append('+{}:{}/{}'.format(ref, REMOTEREFS, ref[len('refs/heads/'):]))
if ref2fetch:
fetch_queue.put((gitrepo, ref2fetch))
+ updated_repos.append(gitrepo)
fetch_queue.join()
@@ -135,7 +139,14 @@ def fetch_packages(options):
if len(refs.heads[dir]) == 0 and os.path.isdir(os.path.join(fulldir, '.git')):
print('Removing', fulldir)
shutil.rmtree(fulldir)
+ return updated_repos
+def clone_packages(options):
+ for repo in fetch_packages(options):
+ try:
+ repo.checkout('master')
+ except GitRepoError as e:
+ print('Problem with checking branch master in repo {}: {}'.format(repo.gdir, e), file=sys.stderr)
common_options = argparse.ArgumentParser(add_help=False)
common_options.add_argument('-d', '--packagesdir', help='local directory with git repositories',
@@ -143,29 +154,36 @@ common_options.add_argument('-d', '--packagesdir', help='local directory with gi
common_options.add_argument('-u', '--user',
help='the user name to register for pushes for new repositories')
+common_fetchoptions = argparse.ArgumentParser(add_help=False, parents=[common_options])
+common_fetchoptions.add_argument('-j', help='number of threads to use', default=4, type=int)
+common_fetchoptions.add_argument('-r', '--remoterefs', help='repository with list of all refs',
+ default=os.path.expanduser('~/PLD_clone/Refs.git'))
+common_fetchoptions.add_argument('repopattern', nargs='*', default = ['*'])
+
parser = argparse.ArgumentParser(description='PLD tool for interaction with git repos',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
subparsers = parser.add_subparsers(help='[-h] [options]')
-update = subparsers.add_parser('update', help='fetch repositories', parents=[common_options],
+update = subparsers.add_parser('update', help='fetch repositories', parents=[common_fetchoptions],
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
update.add_argument('-b', '--branch', help='branch to fetch', action=DelAppend, default=['master'])
update.add_argument('-P', '--prune', help='prune git repositories that do no exist upstream',
action='store_true')
-update.add_argument('-j', help='number of threads to use', default=4, type=int)
update.add_argument('--depth', help='depth of fetch', default=0)
update.add_argument('-n', '--newpkgs', help='download packages that do not exist on local side',
action='store_true')
-update.add_argument('-r', '--remoterefs', help='repository with list of all refs',
- default=os.path.expanduser('~/PLD_clone/Refs.git'))
update.add_argument('repopattern', nargs='*', default = ['*'])
-update.set_defaults(func=fetch_packages)
+update.set_defaults(func=fetch_packages, omitexisting=False)
init = subparsers.add_parser('init', help='init new repository', parents=[common_options],
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
init.add_argument('packages', nargs='+', help='list of packages to create')
init.set_defaults(func=create_packages)
+clone = subparsers.add_parser('clone', help='clone repositorieas', parents=[common_fetchoptions],
+ formatter_class=argparse.ArgumentDefaultsHelpFormatter)
+clone.set_defaults(func=clone_packages, branch='[*]', prune=False, depth=0, newpkgs=True, omitexisting=True)
+
parser.set_defaults(**readconfig(os.path.expanduser('~/.gitconfig')))
options = parser.parse_args()
options.func(options)
================================================================
---- gitweb:
http://git.pld-linux.org/gitweb.cgi/projects/git-slug.git/commitdiff/4ed64f73960519a2f4fd04c42950b2c96ae795c5
More information about the pld-cvs-commit
mailing list