Fix semantics of git new-branch --upstream
Currently, the "--upstream A" option for new-branch behaves totally
different than "--upstream_current". While "--upstream A" checks out
branch A and then creates a new branch which tracks A,
"--upstream_current" creates a new branch for the current HEAD and sets
the upstream to the previously checked out branch.
As the documentation does not mention that any of the options changes
the currently-checked-out commit (HEAD), this CL changes the semantics
of "git new-branch --upstream A B" to be identical to "git checkout -b B
&& git branch --set-upstream-to A".
It also slightly extends the documentation to mention that in any case
the new branch is based on HEAD.
R=iannucci@chromium.org
Change-Id: Ic335d2caf27cb6afca1b8bc5a008424c0e880fca
Reviewed-on: https://chromium-review.googlesource.com/c/1350748
Reviewed-by: Robbie Iannucci <iannucci@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Auto-Submit: Clemens Hammacher <clemensh@chromium.org>
diff --git a/git_new_branch.py b/git_new_branch.py
index d61a42d..105da17 100755
--- a/git_new_branch.py
+++ b/git_new_branch.py
@@ -58,7 +58,8 @@
else:
# TODO(iannucci): Detect unclean workdir then stash+pop if we need to
# teleport to a conflicting portion of history?
- run('checkout', '--track', opts.upstream, '-b', opts.branch_name)
+ run('checkout', '-b', opts.branch_name)
+ run('branch', '--set-upstream-to', opts.upstream)
get_or_create_merge_base(opts.branch_name)
except subprocess2.CalledProcessError as cpe:
sys.stdout.write(cpe.stdout)