mirror of
https://chromium.googlesource.com/chromium/tools/depot_tools.git
synced 2026-01-11 18:51:29 +00:00
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: Edward Lesmes <ehmaldonado@chromium.org> Auto-Submit: Jeffrey Yasskin <jyasskin@chromium.org>
This commit is contained in:
committed by
Commit Bot
parent
fe18a43d59
commit
6b52dc21e1
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user