Commit c68112d9 authored by rmistry@google.com's avatar rmistry@google.com

Stop defaulting unrecognized branches to master except for handful of special refs.

Context:
In https://codereview.chromium.org/781523002/ I added the ability for target_ref to be set to any branch name. Eg: For Skia a ref of 'refs/remotes/origin/chrome/m42' would be correctly set to 'refs/heads/chrome/m42'.

But in https://codereview.chromium.org/822503005/ this was changed to treat any branch that did not start with 'refs/remotes/branch-heads' or 'refs/remotes/origin/refs' to be 'refs/remotes/origin/master'.
This makes it very chromium specific, there are plenty of other projects that use depot_tools that does not work like this.
For Skia 'refs/remotes/origin/chrome/m42' would now change to 'refs/remotes/origin/master' which is wrong.

The default behavior should be to preserve the original ref not to override it to master.

I handled 'lkgr' and 'lkcr' as special cases in this CL because many developers track it and would like it to land in master by default.

BUG=chromium:463109
NOPRESUBMIT=true

Review URL: https://codereview.chromium.org/967453004

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@294303 0039d316-1c4b-4281-b951-d872f2087c98
parent c432a7f7
...@@ -56,6 +56,10 @@ POSTUPSTREAM_HOOK_PATTERN = '.git/hooks/post-cl-%s' ...@@ -56,6 +56,10 @@ POSTUPSTREAM_HOOK_PATTERN = '.git/hooks/post-cl-%s'
DESCRIPTION_BACKUP_FILE = '~/.git_cl_description_backup' DESCRIPTION_BACKUP_FILE = '~/.git_cl_description_backup'
GIT_INSTRUCTIONS_URL = 'http://code.google.com/p/chromium/wiki/UsingGit' GIT_INSTRUCTIONS_URL = 'http://code.google.com/p/chromium/wiki/UsingGit'
CHANGE_ID = 'Change-Id:' CHANGE_ID = 'Change-Id:'
REFS_THAT_ALIAS_TO_OTHER_REFS = {
'refs/remotes/origin/lkgr': 'refs/remotes/origin/master',
'refs/remotes/origin/lkcr': 'refs/remotes/origin/master',
}
# Valid extensions for files we want to lint. # Valid extensions for files we want to lint.
DEFAULT_LINT_REGEX = r"(.*\.cpp|.*\.cc|.*\.h)" DEFAULT_LINT_REGEX = r"(.*\.cpp|.*\.cc|.*\.h)"
...@@ -1790,10 +1794,9 @@ def GetTargetRef(remote, remote_branch, target_branch, pending_prefix): ...@@ -1790,10 +1794,9 @@ def GetTargetRef(remote, remote_branch, target_branch, pending_prefix):
if not match: if not match:
# This is a branch path but not one we recognize; use as-is. # This is a branch path but not one we recognize; use as-is.
remote_branch = target_branch remote_branch = target_branch
elif (not remote_branch.startswith('refs/remotes/branch-heads') and elif remote_branch in REFS_THAT_ALIAS_TO_OTHER_REFS:
not remote_branch.startswith('refs/remotes/%s/refs' % remote)): # Handle the refs that need to land in different refs.
# Default to master for refs that are not branches. remote_branch = REFS_THAT_ALIAS_TO_OTHER_REFS[remote_branch]
remote_branch = 'refs/remotes/%s/master' % remote
# Create the true path to the remote branch. # Create the true path to the remote branch.
# Does the following translation: # Does the following translation:
......
...@@ -822,6 +822,10 @@ class TestGitCl(TestCase): ...@@ -822,6 +822,10 @@ class TestGitCl(TestCase):
git_cl.GetTargetRef('origin', git_cl.GetTargetRef('origin',
'refs/remotes/origin/refs/diff/test', 'refs/remotes/origin/refs/diff/test',
None, None)) None, None))
self.assertEqual('refs/heads/chrome/m42',
git_cl.GetTargetRef('origin',
'refs/remotes/origin/chrome/m42',
None, None))
# Check target refs for user-specified target branch. # Check target refs for user-specified target branch.
for branch in ('branch-heads/123', 'remotes/branch-heads/123', for branch in ('branch-heads/123', 'remotes/branch-heads/123',
......
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