git-upstream-diff: add optional branch argument
Bug: 374928
Change-Id: I8f633ce172fc644e251193eb3fa4b67d62fb9dfa
Reviewed-on: https://chromium-review.googlesource.com/747365
Commit-Queue: Matt Mueller <mattm@chromium.org>
Reviewed-by: Aaron Gable <agable@chromium.org>
diff --git a/git_upstream_diff.py b/git_upstream_diff.py
index c9fdce6..72acb37 100755
--- a/git_upstream_diff.py
+++ b/git_upstream_diff.py
@@ -14,27 +14,34 @@
default_args = git.get_config_list('depot-tools.upstream-diff.default-args')
args = default_args + args
+ current_branch = git.current_branch()
+
parser = argparse.ArgumentParser()
parser.add_argument('--wordwise', action='store_true', default=False,
help=(
'Print a colorized wordwise diff '
'instead of line-wise diff'))
+ parser.add_argument('branch', nargs='?', default=current_branch,
+ help='Show changes from a different branch')
opts, extra_args = parser.parse_known_args(args)
- cur = git.current_branch()
- if not cur or cur == 'HEAD':
+ if not opts.branch or opts.branch == 'HEAD':
print 'fatal: Cannot perform git-upstream-diff while not on a branch'
return 1
- par = git.upstream(cur)
+ par = git.upstream(opts.branch)
if not par:
- print 'fatal: No upstream configured for branch \'%s\'' % cur
+ print 'fatal: No upstream configured for branch \'%s\'' % opts.branch
return 1
cmd = [git.GIT_EXE, 'diff', '--patience', '-C', '-C']
if opts.wordwise:
cmd += ['--word-diff=color', r'--word-diff-regex=(\w+|[^[:space:]])']
- cmd += [git.get_or_create_merge_base(cur, par)]
+ cmd += [git.get_or_create_merge_base(opts.branch, par)]
+ # Only specify the end commit if it is not the current branch, this lets the
+ # diff include uncommitted changes when diffing the current branch.
+ if opts.branch != current_branch:
+ cmd += [opts.branch]
cmd += extra_args