summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xsrc/fedpkg.py25
-rw-r--r--src/pyfedpkg/__init__.py22
2 files changed, 45 insertions, 2 deletions
diff --git a/src/fedpkg.py b/src/fedpkg.py
index c93edb7..0e77d72 100755
--- a/src/fedpkg.py
+++ b/src/fedpkg.py
@@ -266,6 +266,18 @@ def _progress_callback(uploaded, total, piece, time, total_time):
sys.stdout.write("[% -36s] % 4s % 8s % 10s % 14s\r" % ('='*(int(percent_done*36)), percent_done_str, elapsed, data_done, speed))
sys.stdout.flush()
+def switch_branch(args):
+ if args.branch:
+ try:
+ pyfedpkg.switch_branch(args.branch)
+ except pyfedpkg.FedpkgError, e:
+ log.debug('Unable to switch to another branch: %s' % e)
+ else:
+ try:
+ pyfedpkg.switch_branch(list=1)
+ except pyfedpkg.FedpkgError, e:
+ log.debug('Unable to list branches: %s' % e)
+
def build(args):
# We may not actually nave an srpm arg if we come directly from the build task
if hasattr(args, 'srpm') and args.srpm and not args.scratch:
@@ -638,7 +650,16 @@ if __name__ == '__main__':
# Add help to -h and --help
parser_help = subparsers.add_parser('help', help = 'Show usage')
parser_help.set_defaults(command = usage)
-
+
+ # switch branches
+ parser_switchbranch = subparsers.add_parser('switch-branch',
+ help = 'Work with branches')
+ parser_switchbranch.add_argument('branch', nargs = '?')
+ parser_switchbranch.add_argument('-l', '--list',
+ help = 'List both remote-tracking branches and local branches',
+ action = 'store_true')
+ parser_switchbranch.set_defaults(command = switch_branch, replace = True)
+
# Add a common build parser to be used as a parent
parser_build_common = subparsers.add_parser('build_common',
add_help = False)
@@ -910,4 +931,4 @@ packages will be built sequentially.
log.addHandler(streamhandler)
# Run the necessary command
- args.command(args) \ No newline at end of file
+ args.command(args)
diff --git a/src/pyfedpkg/__init__.py b/src/pyfedpkg/__init__.py
index 53b7e3e..799ae97 100644
--- a/src/pyfedpkg/__init__.py
+++ b/src/pyfedpkg/__init__.py
@@ -251,6 +251,28 @@ 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']
+ print "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.