Skip to content

Commit

Permalink
Return 1 if --diff changed the code.
Browse files Browse the repository at this point in the history
This is how GNU diff acts.
  • Loading branch information
bwendling committed Aug 1, 2017
1 parent 010a201 commit eeb6d46
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Expand Up @@ -5,6 +5,7 @@
## [0.16.4] Unreleased
### Changed
- Adjust blank lines on formatting boundaries when using the `--lines` option.
- Return 1 if a diff changed the code. This is in line with how GNU diff acts.

## [0.16.3] 2017-07-13
### Changed
Expand Down
4 changes: 2 additions & 2 deletions yapf/__init__.py
Expand Up @@ -177,7 +177,7 @@ def main(argv):
if not files:
raise errors.YapfError('Input filenames did not match any python files')

FormatFiles(
changed = FormatFiles(
files,
lines,
style_config=args.style,
Expand All @@ -186,7 +186,7 @@ def main(argv):
print_diff=args.diff,
verify=args.verify,
parallel=args.parallel)
return 0
return 1 if changed and args.diff else 0


def FormatFiles(filenames,
Expand Down
5 changes: 4 additions & 1 deletion yapftests/yapf_test.py
Expand Up @@ -492,7 +492,10 @@ def f():
suffix='.py', dirname=self.test_tmpdir) as (out, _):
with utils.TempFileContents(
self.test_tmpdir, unformatted_code, suffix='.py') as filepath:
subprocess.check_call(YAPF_BINARY + ['--diff', filepath], stdout=out)
try:
subprocess.check_call(YAPF_BINARY + ['--diff', filepath], stdout=out)
except subprocess.CalledProcessError as e:
self.assertEqual(e.returncode, 1) # Indicates the text changed.

def testReformattingSpecificLines(self):
unformatted_code = textwrap.dedent("""\
Expand Down

0 comments on commit eeb6d46

Please sign in to comment.