summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Keating <jkeating@redhat.com>2010-08-02 14:19:10 -0700
committerJesse Keating <jkeating@redhat.com>2010-08-02 15:25:07 -0700
commitf63baa10fe44bea53783afbfc28b58e1e79e55d3 (patch)
tree895cf146ecaa85a7535d9a37b3e25b96fb577ee3
parent6d5c91d3bdae3fe73d26289bf79875b732229535 (diff)
downloadfedora-packager-f63baa10fe44bea53783afbfc28b58e1e79e55d3.tar.gz
fedora-packager-f63baa10fe44bea53783afbfc28b58e1e79e55d3.tar.xz
fedora-packager-f63baa10fe44bea53783afbfc28b58e1e79e55d3.zip
Enable branch switching without any rpm content
Without rpm content, we can't init the packagemodule, so don't try to do that when switching branches.
-rwxr-xr-xsrc/fedpkg.py9
-rw-r--r--src/pyfedpkg/__init__.py111
2 files changed, 62 insertions, 58 deletions
diff --git a/src/fedpkg.py b/src/fedpkg.py
index e99c476..dadaa23 100755
--- a/src/fedpkg.py
+++ b/src/fedpkg.py
@@ -592,20 +592,15 @@ def srpm(args):
sys.exit(1)
def switch_branch(args):
- try:
- mymodule = pyfedpkg.PackageModule(args.path)
- except pyfedpkg.FedpkgError, e:
- log.error('Could not init the module')
- sys.exit(1)
if args.branch:
try:
- mymodule.switch_branch(args.branch)
+ pyfedpkg.switch_branch(args.branch, args.path)
except pyfedpkg.FedpkgError, e:
log.error('Unable to switch to another branch: %s' % e)
sys.exit(1)
else:
try:
- (locals, remotes) = mymodule.list_branches()
+ (locals, remotes) = pyfedpkg._list_branches(path=args.path)
except pyfedpkg.FedpkgError, e:
log.error('Unable to list branches: %s' % e)
sys.exit(1)
diff --git a/src/pyfedpkg/__init__.py b/src/pyfedpkg/__init__.py
index cc8dd80..ca98436 100644
--- a/src/pyfedpkg/__init__.py
+++ b/src/pyfedpkg/__init__.py
@@ -183,6 +183,29 @@ def _get_build_arches_from_srpm(srpm, arches):
raise FedpkgError('No compatible build arches found in %s' % srpm)
return archlist
+def _list_branches(path=os.getcwd(), repo=None):
+ """Returns a tuple of local and remote branch names"""
+
+ # Create the repo from path if no repo passed
+ if not repo:
+ repo = git.Repo(path)
+ log.debug('Listing refs')
+ refs = repo.refs
+ # Sort into local and remote branches
+ remotes = []
+ locals = []
+ for ref in refs:
+ if type(ref) == git.Head:
+ log.debug('Found local branch %s' % ref.name)
+ locals.append(ref.name)
+ elif type(ref) == git.RemoteReference:
+ if ref.name == 'origin/HEAD':
+ log.debug('Skipping remote branch alias origin/HEAD')
+ continue # Not useful in this context
+ log.debug('Found remote branch %s' % ref.name)
+ remotes.append(ref.name)
+ return (locals, remotes)
+
def _srpmdetails(srpm):
"""Return a tuple of package name, package files, and upload files."""
@@ -522,6 +545,43 @@ def sources(path, outdir=None):
raise FedpkgError('%s failed checksum' % file)
return
+def switch_branch(branch, path=os.getcwd()):
+ """Switch the working branch
+
+ Will create a local branch if one doesn't already exist,
+ based on origin/<branch>/master
+
+ Logs output and returns nothing.
+ """
+
+ # setup the repo object based on our path
+ try:
+ repo = git.Repo(path)
+ except git.errors.InvalidGitRepositoryError:
+ raise FedpkgError('%s is not a valid repo' % path)
+
+ # Get our list of branches
+ (locals, remotes) = _list_branches(repo=repo)
+
+ if not branch in locals:
+ # We need to create a branch
+ log.debug('No local branch found, creating a new one')
+ if not 'origin/%s/master' % branch in remotes:
+ raise FedpkgError('Unknown remote branch %s' % branch)
+ try:
+ log.info(repo.git.checkout('-b', branch, '--track',
+ 'origin/%s/master' % branch))
+ except: # this needs to be finer grained I think...
+ raise FedpkgError('Could not create branch %s' % branch)
+ else:
+ try:
+ output = repo.git.checkout(branch)
+ # The above shoudl have no output, but stash it anyway
+ log.info("Switched to branch '%s'" % branch)
+ except: # This needs to be finer grained I think...
+ raise FedpkgError('Could not check out %s' % branch)
+ return
+
class Lookaside(object):
""" Object for interacting with the lookaside cache. """
@@ -1162,26 +1222,6 @@ class PackageModule:
_run_command(cmd, shell=True)
return
- def list_branches(self):
- """Returns a tuple of local and remote branch names"""
-
- log.debug('Listing refs')
- refs = self.repo.refs
- # Sort into local and remote branches
- remotes = []
- locals = []
- for ref in refs:
- if type(ref) == git.Head:
- log.debug('Found local branch %s' % ref.name)
- locals.append(ref.name)
- elif type(ref) == git.RemoteReference:
- if ref.name == 'origin/HEAD':
- log.debug('Skipping remote branch alias origin/HEAD')
- continue # Not useful in this context
- log.debug('Found remote branch %s' % ref.name)
- remotes.append(ref.name)
- return (locals, remotes)
-
def local(self, arch=None, hashtype='sha256'):
"""rpmbuild locally for given arch.
@@ -1368,37 +1408,6 @@ class PackageModule:
_run_command(cmd, shell=True)
return
- def switch_branch(self, branch):
- """Switch the working branch
-
- Will create a local branch if one doesn't already exist,
- based on origin/<branch>/master
-
- Logs output and returns nothing.
- """
-
- # Get our list of branches
- (locals, remotes) = self.list_branches()
-
- if not branch in locals:
- # We need to create a branch
- log.debug('No local branch found, creating a new one')
- if not 'origin/%s/master' % branch in remotes:
- raise FedpkgError('Unknown remote branch %s' % branch)
- try:
- log.info(self.repo.git.checkout('-b', branch, '--track',
- 'origin/%s/master' % branch))
- except: # this needs to be finer grained I think...
- raise FedpkgError('Could not create branch %s' % branch)
- else:
- try:
- output = self.repo.git.checkout(branch)
- # The above shoudl have no output, but stash it anyway
- log.info("Switched to branch '%s'" % branch)
- except: # This needs to be finer grained I think...
- raise FedpkgError('Could not check out %s' % branch)
- return
-
def unused_patches(self):
"""Discover patches checked into source control that are not used