rtfpessoa/diff2html-cli

Output file not showing all changed files when using diff -ru

Closed this issue · 9 comments

diff2html handles modifications perfectly, but it seems to ignore both new files and deleted files.

I'm running diff2html via the cli. For reference: diff2html 2.3.0, diff2html-cli 2.5.0. I'm using this to diff between my working SVN directory and my web directory (where I've made several changes).

I've tried pipping the diff directly to diff2html and outputting the diff in a file and then using diff2html with file input, but the result is always the same. I'll get a perfect list/display of all my modified files, but nothing about deleted/new files.

To be sure, I checked the raw diff output, and I definitely see references to both deleted and new files:
-- Only in /localpath/src/views: filename.php (for an added file)
-- Only in /svnpath/src/views: anotherfile.php (for a removed file)

COMMAND: Pipping
diff --exclude=.svn -ru /localpath /svpath | diff2html -F /var/www/html/diff-out.html -i stdin

COMMAND: By File
diff --exclude=.svn -ru /localpath /svpath > diffOut.txt
diff2html -F /var/www/html/diff-out.html -i file "diffOut.txt"

I tried removing the --exclude param, but I still don't see removed or new files in the diff2html output.

I looked around for examples of new and deleted files with diff2html and couldn't find any. I'm assuming diff2html supports deleted/new files because I saw an issue about ordering deleted/new files (github @ rtfpessoa/diff2html#33 ), but I don't see anything about a command line argument to pass for diff2html-cli and was unable to find anyone else with this same problem.

This unified diff output is from the following command:
diff --exclude=.svn -ru /home/vagrant/projects/svn/project-name /var/www/html/sandbox/vendor/vendor-name/project-name > diffOut.txt

I've attached diffOut.txt and a screenshot of the diff2html file, which shows 6 changed files (but no new files). Let me know if you need anything else.

[removed attachments]

diff2html only finds new files because git diff provides extra information. Since you are using diff it cannot know if the file is new in the same way.

Maybe it can be done by checking if all the lines are new or deleted.

Could be a nice improvement to do. If you are interested a PR would be nice.

We could perform the check here https://github.com/rtfpessoa/diff2html/blob/master/src/diff-parser.js#L64

Definitely interested. Could you give me a file with sample output from a git diff with modified as well as new / removed files? That would show me what diff2html expects and give me a comparison to start with.

A new file git diff would look like this:

diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
new file mode 100644
index 0000000..2c12dfc
--- /dev/null
+++ b/CONTRIBUTING.md
@@ -0,0 +1,62 @@
+## How to contribute to diff2html-cli
+
+### Main rules
+
+* Before you open a ticket or send a pull request, [search](https://github.com/rtfpessoa/diff2html-cli/issues) for previous discussions about the same feature or issue. Add to the earlier ticket if you find one.

But in your case I think the best way would be just to check if all the lines in the file are new or remove when adding the file to the list after parsing it.

I found that no code update is necessary. I discovered that diff2html will report new files, you need only pass --new-file to diff:

I was running:
diff --exclude=.svn -ru /localpath /svpath | diff2html -F /var/www/html/diff-out.html -i stdin

"New File" flag:
diff --exclude=.svn --new-file -ru /localpath /svpath | diff2html -F /var/www/html/diff-out.html -i stdin

New and deleted files now appear in the diff2html! :) No code changes necessary. Sorry for raising a non-issue...

Ok. Nice no problem.

Still I might pick this when I get some time since it is nice if I can detect this files even without the extra info.

pbu88 commented

Just a small note, checking if all the lines are added or deleted might be a legit case of a non-new/deleted file. Say you decide to delete all the lines in a file to start new (or because is part of some process). Same for additions. Is unlikely, but people use git in very different ways.

Finding the right command I think is the best approach. Is not diff2html responsibility to try to figure out what you are trying to do in my opinion.

@pbu88 good point.