git-js icon indicating copy to clipboard operation
git-js copied to clipboard

Add patch to DiffSummary when using log -p

Open calaoa opened this issue 4 years ago • 5 comments

Steps to reproduce

  • Run the log function with options {"-p": null}

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

  • node 13.13.0
  • typescript 3.8.3
  • simple-git: 1.132.0

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 avatar Apr 24 '20 09:04 calaoa

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

calaoa avatar Apr 29 '20 09:04 calaoa

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.

steveukx avatar Apr 29 '20 09:04 steveukx

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 avatar Apr 29 '20 10:04 calaoa

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 avatar May 13 '20 07:05 calaoa

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.

calaoa avatar May 16 '20 06:05 calaoa