Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Unified Diff: scm.py

Issue 1739021: Modify scm.GIT.GetUpstreamBranch to behave like git-cl. (Closed)
Patch Set: Created 10 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « gclient_scm.py ('k') | tests/scm_unittest.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: scm.py
diff --git a/scm.py b/scm.py
index cbb44f26781a822bb6897d6754070b394d0c3ab2..c4834116f9818a8a4c4f77596f8b5e5cb6922bbf 100644
--- a/scm.py
+++ b/scm.py
@@ -202,6 +202,7 @@ class GIT(object):
def FetchUpstreamTuple(cwd):
"""Returns a tuple containg remote and remote ref,
e.g. 'origin', 'refs/heads/master'
+ Tries to be intelligent and understand git-svn.
"""
remote = '.'
branch = GIT.GetBranch(cwd)
@@ -217,10 +218,18 @@ class GIT(object):
# Fall back on trying a git-svn upstream branch.
if GIT.IsGitSvn(cwd):
upstream_branch = GIT.GetSVNBranch(cwd)
+ # Fall back on origin/master if it exits.
+ elif GIT.Capture(['branch', '-r'], in_directory=cwd
+ )[0].split().count('origin/master'):
+ remote = 'origin'
+ upstream_branch = 'refs/heads/master'
+ else:
+ remote = None
+ upstream_branch = None
return remote, upstream_branch
@staticmethod
- def GetUpstream(cwd):
+ def GetUpstreamBranch(cwd):
"""Gets the current branch's upstream branch."""
remote, upstream_branch = GIT.FetchUpstreamTuple(cwd)
if remote != '.':
@@ -235,7 +244,7 @@ class GIT(object):
full_move means that move or copy operations should completely recreate the
files, usually in the prospect to apply the patch for a try job."""
if not branch:
- branch = GIT.GetUpstream(cwd)
+ branch = GIT.GetUpstreamBranch(cwd)
command = ['diff', '-p', '--no-prefix', branch + "..." + branch_head]
if not full_move:
command.append('-C')
@@ -255,7 +264,7 @@ class GIT(object):
def GetDifferentFiles(cwd, branch=None, branch_head='HEAD'):
"""Returns the list of modified files between two branches."""
if not branch:
- branch = GIT.GetUpstream(cwd)
+ branch = GIT.GetUpstreamBranch(cwd)
command = ['diff', '--name-only', branch + "..." + branch_head]
return GIT.Capture(command, cwd)[0].splitlines(False)
« no previous file with comments | « gclient_scm.py ('k') | tests/scm_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698