From 43a3413a1179eb862a7f2d305bab8bdc5db7ef84 Mon Sep 17 00:00:00 2001 From: Markus Lehtonen Date: Tue, 16 Oct 2012 11:01:07 +0300 Subject: [PATCH] submit: try to guess the remote server If the current branch has upstream set, use it's remote as the server to push to. Only uses 'origin' as default if no upstream is set. Signed-off-by: Markus Lehtonen --- gitbuildsys/cmd_submit.py | 31 +++++++++++++++++++------------ tools/gbs | 6 +++--- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/gitbuildsys/cmd_submit.py b/gitbuildsys/cmd_submit.py index 2447070..baaa6aa 100644 --- a/gitbuildsys/cmd_submit.py +++ b/gitbuildsys/cmd_submit.py @@ -44,18 +44,25 @@ def main(args): except GitRepositoryError, err: msger.error(str(err)) + try: + upstream = repo.get_upstream_branch(target_branch) + except GitRepositoryError: + pass + if not args.remote: + if upstream: + args.remote = upstream.split('/')[0] + else: + msger.info("no upstream set for the current branch, using " + "'origin' as the remote server") + args.remote = 'origin' if not args.target: - try: - upstream = repo.get_upstream_branch(target_branch) - if upstream and upstream.startswith(args.remote): - target_branch = os.path.basename(upstream) - else: - msger.warning('can\'t find upstream branch for current branch '\ - '%s. Gbs will try to find it by name. Please '\ - 'consider to use git-branch --set-upstream to '\ - 'set upstream remote branch.' % target_branch) - except GitRepositoryError: - pass + if upstream and upstream.startswith(args.remote): + target_branch = os.path.basename(upstream) + else: + msger.warning('can\'t find upstream branch for current branch '\ + '%s. Gbs will try to find it by name. Please '\ + 'consider to use git-branch --set-upstream to '\ + 'set upstream remote branch.' % target_branch) try: if target_branch == 'master': @@ -69,7 +76,7 @@ def main(args): msger.error('failed to create tag %s: %s ' % (tagname, str(err))) try: - msger.info('pushing tag to remote server') + msger.info("pushing tag to remote '%s'" % args.remote) repo.push_tag(args.remote, tagname) except GitRepositoryError, err: repo.delete_tag(tagname) diff --git a/tools/gbs b/tools/gbs index b817690..a79670a 100755 --- a/tools/gbs +++ b/tools/gbs @@ -301,9 +301,9 @@ def submit_parser(parser): help='using the given key to make a GPG-signed tag') parser.add_argument('-t', '--target', help='specify target version to submit, eg: trunk.') - parser.add_argument('-r', '--remote', default='origin', - help='specify gerrit project server, default value is ' - 'origin for example:\nssh://user@review.tizen.org:29418' + parser.add_argument('-r', '--remote', + help='specify gerrit project server, ' + 'for example:\nssh://user@review.tizen.org:29418' '/public/base/gcc') parser.set_defaults(alias="sr") -- 2.7.4