summaryrefslogtreecommitdiffstats
path: root/src/pyfedpkg/__init__.py
diff options
context:
space:
mode:
authorJesse Keating <jkeating@redhat.com>2010-07-23 18:07:28 -0700
committerJesse Keating <jkeating@redhat.com>2010-07-23 18:07:28 -0700
commit26b2ed80839c521a6b79fafda008220918ac05b5 (patch)
tree7e35084d5d26b4141454643787b3ea84e407fa76 /src/pyfedpkg/__init__.py
parent35eb92bea31c3cd8ce26d3e94b6d784ae5faa53f (diff)
downloadfedora-packager-26b2ed80839c521a6b79fafda008220918ac05b5.tar.gz
fedora-packager-26b2ed80839c521a6b79fafda008220918ac05b5.tar.xz
fedora-packager-26b2ed80839c521a6b79fafda008220918ac05b5.zip
Rework how we deal with branches
Create a new list_branches function to discover the local and remote branches. Allow creating a new branch if the requested local branch doesn't already exist.
Diffstat (limited to 'src/pyfedpkg/__init__.py')
-rw-r--r--src/pyfedpkg/__init__.py73
1 files changed, 51 insertions, 22 deletions
diff --git a/src/pyfedpkg/__init__.py b/src/pyfedpkg/__init__.py
index 1a48b81..07b3d60 100644
--- a/src/pyfedpkg/__init__.py
+++ b/src/pyfedpkg/__init__.py
@@ -253,28 +253,6 @@ def clean(dry=False, useignore=True):
log.error(error)
return proc.returncode
-def switch_branch(branch=None, list=None):
- """Work with different branches.
-
- branch is the name of the branch to switch to
-
- Logs output and returns nothing.
- """
- if list:
- cmd = ['git', 'branch']
- log.info('Listing branches')
- cmd.extend(['-a'])
- _run_command(cmd)
- else:
- cmd = ['git', 'checkout']
- cmd.extend([branch])
- log.debug('Switching to branch %s' % branch)
- try:
- _run_command(cmd)
- except FedpkgError:
- sys.exit(1)
- return
-
def clone(module, user, path=os.getcwd(), branch=None, bare_dir=None):
"""Clone a repo, optionally check out a specific branch.
@@ -1107,6 +1085,26 @@ 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.
@@ -1331,6 +1329,37 @@ 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