[projects/git-slug: 136/170] Checkout command to checkout one branch in all repositories
glen
glen at pld-linux.org
Mon Sep 21 21:50:14 CEST 2015
commit c928e366617a283c06fda52944cc9eadb82d3e80
Author: Kacper Kornet <draenog at pld-linux.org>
Date: Thu Jul 5 15:06:32 2012 +0100
Checkout command to checkout one branch in all repositories
slug.py | 20 +++++++++++++++++++-
slug.py.txt | 13 +++++++++++++
2 files changed, 32 insertions(+), 1 deletion(-)
---
diff --git a/slug.py b/slug.py
index 6c5d113..267f37a 100755
--- a/slug.py
+++ b/slug.py
@@ -14,7 +14,7 @@ import argparse
import signal
import configparser
-from git_slug.gitconst import GITLOGIN, GITSERVER, GIT_REPO, GIT_REPO_PUSH, REMOTEREFS
+from git_slug.gitconst import GITLOGIN, GITSERVER, GIT_REPO, GIT_REPO_PUSH, REMOTE_NAME, REMOTEREFS
from git_slug.gitrepo import GitRepo, GitRepoError
from git_slug.refsdata import GitArchiveRefsData, NoMatchedRepos, RemoteRefsError
@@ -136,6 +136,18 @@ def fetch_packages(options):
shutil.rmtree(fulldir)
return updated_repos
+def checkout_packages(options):
+ if options.checkout is None:
+ options.checkout = "/".join([REMOTE_NAME, options.branch[0]])
+ fetch_packages(options)
+ refs = getrefs(options.branch, options.repopattern)
+ for pkgdir in sorted(refs.heads):
+ repo = GitRepo(os.path.join(options.packagesdir, pkgdir))
+ try:
+ repo.checkout(options.checkout)
+ except GitRepoError as e:
+ print('Problem with checking branch {} in repo {}: {}'.format(options.checkout, repo.gdir, e), file=sys.stderr)
+
def clone_packages(options):
for repo in fetch_packages(options):
try:
@@ -185,6 +197,12 @@ fetch = subparsers.add_parser('fetch', help='fetch repositories', parents=[commo
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
fetch.set_defaults(func=fetch_packages, branch='[*]', prune=False, newpkgs=False, omitexisting=False)
+checkout =subparsers.add_parser('checkout', help='checkout repositories', parents=[common_fetchoptions],
+ formatter_class=argparse.ArgumentDefaultsHelpFormatter)
+checkout.add_argument('-b', '--branch', help='branch to fetch', action=DelAppend, default=['master'])
+checkout.add_argument('-c', '--checkout', help='branch to fetch', default=None)
+checkout.set_defaults(func=checkout_packages, newpkgs=True, omitexisting=False)
+
listpkgs = subparsers.add_parser('list', help='list repositories',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
listpkgs.add_argument('-b', '--branch', help='show packages with given branch', action=DelAppend, default=['*'])
diff --git a/slug.py.txt b/slug.py.txt
index b87854a..2bf5014 100644
--- a/slug.py.txt
+++ b/slug.py.txt
@@ -40,6 +40,19 @@ OPTIONS
COMMANDS
--------
+'checkout' <pattern>...::
+
+Update the remote branches in the set of packages that match at least one of patterns and checkouts the first
+branch in all repositories matching at least one of <patterns>.
+ -b <pattern>;;
+ --branch <pattern>;;
+ Only the remote branches which names match the pattern are updated. If omitted \'master'
+ is assumed.
+ -c;;
+ --checkout <ref>;;
+ Name of ref to checkout. If omitted the remote tracking branch corresponding to the argument of
+ the first -b option is assumed.
+
'clone' <pattern> ...::
Clone the repositories which names match at least one of <patterns>.
================================================================
---- gitweb:
http://git.pld-linux.org/gitweb.cgi/projects/git-slug.git/commitdiff/4ed64f73960519a2f4fd04c42950b2c96ae795c5
More information about the pld-cvs-commit
mailing list