Index: git_cl.py |
diff --git a/git_cl.py b/git_cl.py |
index d9e2d9803b0203d3203e61721d4e9b6fced0f616..b1cf7fa2695ad42fd316c3f0bfa158c0bf7c203b 100755 |
--- a/git_cl.py |
+++ b/git_cl.py |
@@ -2303,6 +2303,7 @@ def CMDowners(parser, args): |
disable_color=options.no_color).run() |
+@subcommand.usage('[files or directories to diff]') |
def CMDformat(parser, args): |
"""Runs clang-format on the diff.""" |
CLANG_EXTS = ['.cc', '.cpp', '.h'] |
@@ -2311,8 +2312,6 @@ def CMDformat(parser, args): |
parser.add_option('--dry-run', action='store_true', |
help='Don\'t modify any file on disk.') |
opts, args = parser.parse_args(args) |
- if args: |
- parser.error('Unrecognized args: %s' % ' '.join(args)) |
# git diff generates paths against the root of the repository. Change |
# to that directory so clang-format can find files even within subdirs. |
@@ -2348,7 +2347,16 @@ def CMDformat(parser, args): |
# Handle source file filtering. |
diff_cmd.append('--') |
- diff_cmd += ['*' + ext for ext in CLANG_EXTS] |
+ if args: |
+ for arg in args: |
+ if os.path.isdir(arg): |
+ diff_cmd += [os.path.join(arg, '*' + ext) for ext in CLANG_EXTS] |
iannucci
2014/01/29 06:06:03
Is clang format interpreting these globs? Because
enne (OOO)
2014/01/29 18:18:31
According to https://www.kernel.org/pub/software/s
|
+ elif os.path.isfile(arg): |
+ diff_cmd.append(arg) |
+ else: |
+ DieWithError('Argument "%s" is not a file or a directory' % arg) |
+ else: |
+ diff_cmd += ['*' + ext for ext in CLANG_EXTS] |
diff_output = RunGit(diff_cmd) |
top_dir = os.path.normpath( |