Commit 6b52dc21 authored by Jeffrey Yasskin's avatar Jeffrey Yasskin Committed by Commit Bot

Default to origin's default branch instead of always origin/master.

BUG=1023031

Change-Id: I4bf3e33932af40600646f070f057a7c8c0661f33
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1954624
Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
Reviewed-by: 's avatarEdward Lesmes <ehmaldonado@chromium.org>
Auto-Submit: Jeffrey Yasskin <jyasskin@chromium.org>
parent fe18a43d
......@@ -665,8 +665,16 @@ def repo_root():
return run('rev-parse', '--show-toplevel')
def upstream_default():
"""Returns the default branch name of the origin repository."""
try:
return run('rev-parse', '--abbrev-ref', 'origin/HEAD')
except subprocess2.CalledProcessError:
return 'origin/master'
def root():
return get_config('depot-tools.upstream', 'origin/master')
return get_config('depot-tools.upstream', upstream_default())
@contextlib.contextmanager
......
......@@ -52,7 +52,8 @@ depot-tools.upstream
~~~~~~~~~~~~~~~~~~~~
This configures the default 'upstream' for all new branches. If it is unset, it
defaults to 'origin/master'. This is considered to be the 'root' branch.
defaults to 'origin''s default branch or 'origin/master' if that can't be found.
This is considered to be the 'root' branch.
EXAMPLE
-------
......
......@@ -63,7 +63,7 @@ Restoration::
`git rebase-update` checks out the branch that you started on, and 'thaws' it,
if necessary (see linkgit:git-thaw[1]). If the branch you started on got
cleaned up, `git rebase-update` will checkout the 'root' ref (defaults to
'origin/master', as configured by `depot-tools.upstream`, see
'origin''s default branch, as configured by `depot-tools.upstream`, see
linkgit:git-new-branch[1]).
......
......@@ -453,6 +453,20 @@ class GitMutableFunctionsTest(git_test_utils.GitRepoReadWriteTestBase,
self.assertEqual('catfood', self.repo.run(self.gc.root))
def testRoot(self):
origin_schema = git_test_utils.GitRepoSchema("""
A B C
B D
""", self.getRepoContent)
origin = origin_schema.reify()
# Set the default branch to branch_D instead of master.
origin.git('checkout', 'branch_D')
self.repo.git('remote', 'add', 'origin', origin.repo_path)
self.repo.git('fetch', 'origin')
self.repo.git('remote', 'set-head', 'origin', '-a')
self.assertEqual('origin/branch_D', self.repo.run(self.gc.root))
def testUpstream(self):
self.repo.git('commit', '--allow-empty', '-am', 'foooooo')
self.assertEqual(self.repo.run(self.gc.upstream, 'bobly'), None)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment