Chromium Code Reviews| Index: git_cl.py |
| diff --git a/git_cl.py b/git_cl.py |
| index 289640a77cc0b1962faf9dc8c50abaabe8bd4f35..18e02b2e0da9565c365ad91e81bc0243da215f0c 100755 |
| --- a/git_cl.py |
| +++ b/git_cl.py |
| @@ -1861,7 +1861,18 @@ def CMDpatch(parser, args): |
| # TODO(maruel): Use apply_issue.py |
| # TODO(ukai): use gerrit-cherry-pick for gerrit repository? |
| - if issue_arg.isdigit(): |
| + if options.newbranch: |
| + if options.force: |
| + RunGit(['branch', '-D', options.newbranch], |
| + stderr=subprocess2.PIPE, error_ok=True) |
| + RunGit(['checkout', '-b', options.newbranch, |
| + Changelist().GetUpstreamBranch()]) |
| + |
| + return PatchIssue(issue_arg, options.reject, options.nocommit) |
| + |
| + |
| +def PatchIssue(issue_arg, reject, nocommit): |
| + if type(issue_arg) is int or issue_arg.isdigit(): |
| # Input is an issue id. Figure out the URL. |
| issue = int(issue_arg) |
| cl = Changelist(issue=issue) |
| @@ -1878,13 +1889,6 @@ def CMDpatch(parser, args): |
| patchset = int(match.group(2)) |
| patch_data = urllib2.urlopen(issue_arg).read() |
| - if options.newbranch: |
| - if options.force: |
| - RunGit(['branch', '-D', options.newbranch], |
| - stderr=subprocess2.PIPE, error_ok=True) |
| - RunGit(['checkout', '-b', options.newbranch, |
| - Changelist().GetUpstreamBranch()]) |
| - |
| # Switch up to the top-level directory, if necessary, in preparation for |
| # applying the patch. |
| top = RunGit(['rev-parse', '--show-cdup']).strip() |
| @@ -1909,7 +1913,7 @@ def CMDpatch(parser, args): |
| # pick up file adds. |
| # The --index flag means: also insert into the index (so we catch adds). |
| cmd = ['git', 'apply', '--index', '-p0'] |
| - if options.reject: |
| + if reject: |
| cmd.append('--reject') |
| elif IsGitVersionAtLeast('1.7.12'): |
| cmd.append('--3way') |
| @@ -1920,7 +1924,7 @@ def CMDpatch(parser, args): |
| DieWithError('Failed to apply the patch') |
| # If we had an issue, commit the current state and register the issue. |
| - if not options.nocommit: |
| + if not nocommit: |
| RunGit(['commit', '-m', 'patch from issue %s' % issue]) |
| cl = Changelist() |
| cl.SetIssue(issue) |
| @@ -2128,6 +2132,31 @@ def CMDset_close(parser, args): |
| return 0 |
| +def CMDdiff(parser, args): |
| + """show differences between local tree and last upload.""" |
|
M-A Ruel
2013/09/20 15:08:16
shows
Sam Clegg
2013/09/23 16:38:42
Done.
|
| + cl = Changelist() |
| + branch = cl.GetBranch() |
| + TMP_BRANCH = 'git-cl-diff' |
| + base_branch = RunGit(['merge-base', cl.GetUpstreamBranch(), 'HEAD']).strip() |
| + |
| + # Create a new branch based on the merge-base |
| + RunGit(['checkout', '-q', '-b', TMP_BRANCH, base_branch]) |
| + try: |
| + # Patch in the latest changes from rietveld. |
| + rtn = PatchIssue(cl.GetIssue(), False, False) |
| + if rtn != 0: |
| + return rtn |
| + |
| + # Switch back to starting brand and diff against the temporary |
| + # branch containing the latest rietveld patch. |
| + RunGit(['checkout', '-q', branch]) |
| + print RunGit(['diff', TMP_BRANCH]) |
|
M-A Ruel
2013/09/20 15:08:16
Use subprocess2.call(['git', ...]) instead, so col
Sam Clegg
2013/09/23 16:38:42
Done.
|
| + finally: |
| + RunGit(['branch', '-D', TMP_BRANCH]) |
|
M-A Ruel
2013/09/20 15:08:16
I think RunGit(['checkout', '-q', branch]) should
Sam Clegg
2013/09/23 16:38:42
Done.
|
| + |
| + return 0 |
| + |
| + |
| def CMDowners(parser, args): |
| """interactively find the owners for reviewing""" |
| parser.add_option( |