steveukx / git-js

A light weight interface for running git commands in any node.js application.
MIT License
3.48k stars 315 forks source link

Add patch to DiffSummary when using log -p #440

Open calaoa opened 4 years ago

calaoa commented 4 years ago

Steps to reproduce

Actual result

The returned data contains a DiffSummary object but it seems to be empty while the log obtained via the git command line is not (see detailed output example below for a given commit).

Environment

Example

ListLogLine obtained via simple-git

  latest: ListLogLine {
    hash: '4d1086b773a2468c971030a9cef5bd3fe3a9ad31',
    date: '2020-04-24 11:02:47 +0200',
    message: '',
    refs: 'HEAD -> master',
    body: '',
    author_name: 'calaotok',
    author_email: 'calaotok',
    diff: DiffSummary { files: [], insertions: 0, deletions: 0, changed: 0 }
  }

Log line obtained via git for the same commit

commit 4d1086b773a2468c971030a9cef5bd3fe3a9ad31
Author: calaotok <calaotok>
Date:   Fri Apr 24 11:02:47 2020 +0200

diff --git a/calaotok/tav.md b/calaotok/tav.md
index 3f12934..20c9aef 100644
--- a/calaotok/tav.md
+++ b/calaotok/tav.md
@@ -17,4 +17,6 @@ qmqm

 qmqmq

+sldsfkjjajaja
+ 
calaoa commented 4 years ago

Is anyone experiencing the same issue or is it more me misusing the API? The lib is awesome by the way, thumbs up.

steveukx commented 4 years ago

Hi & thank you for the 👍, there isn't a parser built into the library that supports the patch (-p) response format, which is why the response appears empty...

If you have a parser available to you (perhaps something like diff2html would help) then you can get the raw response from git using await git.raw(['log', '-p']).

If you need the summary detail without the full patch detail, remove the -p option and the response should contain all the expected detail - you can choose which details are included by setting the formats option object to have any of the supported pretty format constants.

calaoa commented 4 years ago

Thanks a lot for the guidance. I had overlooked the raw function, cool, even though a real integration into the library would be a handy enhancement indeed.

My use case is the following: collaborative notes are versioned via git and the users want to browse the recent changes in a row without the need to click on each individual commit to view the actual updates, hence the need for the -p switch, I guess.

I started looking into SimpleGit.log code, I'll see if I can come up with a patch proposal (not sure, will try).

calaoa commented 4 years ago

Just a quick note to ask whether the pull request I submitted for this issue makes any sense indeed and if there's a chance it can be merged (no hurry, just asking) /cheers + thumbs up

calaoa commented 4 years ago

On second thoughts, it's probably not a good idea to have added a dependency to diff2html in #444 since developers might prefer other parsing libraries. Meantime I proceeded as you suggested @steveukx : I invoked the raw function, for now with a copy of the ListLogSummary parser, completed by a diff2html call, thanks for your guidance. Exporting the ListLogSummary parser might be useful so that it can be used by customized parsers, what do you think (or adding a hook to it for injecting patch parsing)? Closing #444.