Add the ability to set the upstream branch

I can never remember the syntax (and always forget I have to specify the branch to set the upstream branch on) when using "git branch".

This patch just allows git-cl upstream to set the branch if an argument is provided. With no arg it prints the current one as it does today.

Review URL: https://chromiumcodereview.appspot.com/10825285

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@150945 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/git_cl.py b/git_cl.py
index 9716ef1..452858a 100755
--- a/git_cl.py
+++ b/git_cl.py
@@ -1514,13 +1514,22 @@
   return 0
 
 
+@usage('[new upstream branch]')
 def CMDupstream(parser, args):
-  """print the name of the upstream branch, if any"""
+  """prints or sets the name of the upstream branch, if any"""
   _, args = parser.parse_args(args)
-  if args:
+  if len(args) > 1:
     parser.error('Unrecognized args: %s' % ' '.join(args))
+    return 0
+
   cl = Changelist()
-  print cl.GetUpstreamBranch()
+  if args:
+    # One arg means set upstream branch.
+    RunGit(['branch', '--set-upstream', cl.GetBranch(), args[0]])
+    cl = Changelist()
+    print "Upstream branch set to " + cl.GetUpstreamBranch()
+  else:
+    print cl.GetUpstreamBranch()
   return 0