From ad26434b3b8a5eafab8ec52b83aa99beaf48fb03 Mon Sep 17 00:00:00 2001 From: Russell Belfer Date: Tue, 9 Apr 2013 14:52:32 -0700 Subject: Tests and more fixes for submodule diffs This adds tests for diffs with submodules in them and (perhaps unsurprisingly) requires further fixes to be made. Specifically, this fixes: - when considering if a submodule is dirty in the workdir, it was being treated as dirty even if only the index was dirty. - git_diff_patch_to_str (and git_diff_patch_print) were "printing" the headers for files (and submodules) that were unmodified or had no meaningful content. - added comment to previous fix and removed unneeded parens. --- src/diff_output.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src/diff_output.c') diff --git a/src/diff_output.c b/src/diff_output.c index d462142f9..34a3e506c 100644 --- a/src/diff_output.c +++ b/src/diff_output.c @@ -675,11 +675,14 @@ cleanup: if (!error) { patch->flags |= GIT_DIFF_PATCH_LOADED; + /* patch is diffable only for non-binary, modified files where at + * least one side has data and there is actual change in the data + */ if ((delta->flags & GIT_DIFF_FLAG_BINARY) == 0 && delta->status != GIT_DELTA_UNMODIFIED && (patch->old_data.len || patch->new_data.len) && - ((patch->old_data.len != patch->new_data.len) || - !git_oid_equal(&delta->old_file.oid, &delta->new_file.oid))) + (patch->old_data.len != patch->new_data.len || + !git_oid_equal(&delta->old_file.oid, &delta->new_file.oid))) patch->flags |= GIT_DIFF_PATCH_DIFFABLE; } @@ -1150,7 +1153,11 @@ static int print_patch_file( GIT_UNUSED(progress); - if (S_ISDIR(delta->new_file.mode)) + if (S_ISDIR(delta->new_file.mode) || + delta->status == GIT_DELTA_UNMODIFIED || + delta->status == GIT_DELTA_IGNORED || + (delta->status == GIT_DELTA_UNTRACKED && + (pi->diff->opts.flags & GIT_DIFF_INCLUDE_UNTRACKED_CONTENT) == 0)) return 0; if (!oldpfx) -- cgit v1.2.1