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

Side by Side Diff: git_upstream_diff.py

Issue 212493002: Make udiff print reasonable errors while not on a branch. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 6 years, 9 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2014 The Chromium Authors. All rights reserved. 2 # Copyright 2014 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 import argparse 6 import argparse
7 import sys 7 import sys
8 8
9 import subprocess2 9 import subprocess2
10 10
11 from git_common import current_branch, get_or_create_merge_base, config_list 11 from git_common import current_branch, get_or_create_merge_base, config_list
agable 2014/03/26 15:36:24 Would be good to sort these imports.
iannucci 2014/03/26 18:51:11 Done.
12 from git_common import GIT_EXE 12 from git_common import GIT_EXE, upstream
13 13
14 def main(args): 14 def main(args):
15 default_args = config_list('depot-tools.upstream-diff.default-args') 15 default_args = config_list('depot-tools.upstream-diff.default-args')
16 args = default_args + args 16 args = default_args + args
17 17
18 parser = argparse.ArgumentParser() 18 parser = argparse.ArgumentParser()
19 parser.add_argument('--wordwise', action='store_true', default=False, 19 parser.add_argument('--wordwise', action='store_true', default=False,
20 help=( 20 help=(
21 'Print a colorized wordwise diff ' 21 'Print a colorized wordwise diff '
22 'instead of line-wise diff')) 22 'instead of line-wise diff'))
23 opts, extra_args = parser.parse_known_args(args) 23 opts, extra_args = parser.parse_known_args(args)
24 24
25 cur = current_branch()
26 if not cur or cur == 'HEAD':
27 print 'fatal: cannot perform git-upstream-diff while not on a branch'
28 return 1
29
30 par = upstream(cur)
31 if not par:
32 print 'fatal: branch %s has no configured upstream' % cur
agable 2014/03/26 15:36:24 fatal: branch.%s.merge is not configured ?
iannucci 2014/03/26 18:51:11 Yeah, but it's also ...remote. I'm changing to the
33 return 1
34
25 cmd = [GIT_EXE, 'diff', '--patience', '-C', '-C'] 35 cmd = [GIT_EXE, 'diff', '--patience', '-C', '-C']
26 if opts.wordwise: 36 if opts.wordwise:
27 cmd += ['--word-diff=color', r'--word-diff-regex=(\w+|[^[:space:]])'] 37 cmd += ['--word-diff=color', r'--word-diff-regex=(\w+|[^[:space:]])']
28 cmd += [get_or_create_merge_base(current_branch())] 38 cmd += [get_or_create_merge_base(cur, par)]
29 39
30 cmd += extra_args 40 cmd += extra_args
31 41
32 subprocess2.check_call(cmd) 42 subprocess2.check_call(cmd)
33 43
34 44
35 if __name__ == '__main__': 45 if __name__ == '__main__':
36 sys.exit(main(sys.argv[1:])) 46 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698