Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added --new-file option for GNU diff compatibility #218

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions icdiff
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,11 @@ def create_option_parser():
help="compare the file permissions as well as the "
"content of the file",
)
parser.add_option(
"--new-file",
default=False,
action="store_true"
)
parser.add_option(
"--strip-trailing-cr",
default=False,
Expand Down Expand Up @@ -834,6 +839,7 @@ def diff(options, a, b):
is_a_file = not os.path.isdir(a)
is_b_file = not os.path.isdir(b)


if is_a_file and is_b_file:
try:
if not (
Expand All @@ -856,13 +862,23 @@ def diff(options, a, b):
for child in sorted(a_contents.union(b_contents)):
if should_be_excluded(child, options.exclude):
continue

a_file_path = os.path.join(a, child)
b_file_path = os.path.join(b, child)

if child not in b_contents:
print_meta("Only in %s: %s" % (a, child))
if not options.new_file:
print_meta("Only in %s: %s" % (a, child))
continue
b_file_path = os.devnull
elif child not in a_contents:
print_meta("Only in %s: %s" % (b, child))
elif options.recursive:
if not options.new_file:
print_meta("Only in %s: %s" % (b, child))
continue
a_file_path = os.devnull
if options.recursive:
diffs_found = diffs_found | diff(
options, os.path.join(a, child), os.path.join(b, child)
options, a_file_path, b_file_path
)
elif not is_a_file and is_b_file:
print_meta("File %s is a directory while %s is a file" % (a, b))
Expand Down