majkinetor / au

Chocolatey Automatic Package Updater Module
GNU General Public License v2.0
227 stars 71 forks source link

History plugin not parsing date correctly #258

Closed danmetzler closed 2 years ago

danmetzler commented 2 years ago

I'm using Git version 2.34.1, and seem to be getting errors in the History plugin.

Appears the issue is [here](https://github.com/majkinetor/au/blob/master/AU/Plugins/History.ps1#:~:text=%24date%20%20%20%20%20%3D%20%24commit%5B2%5D.Replace(%27Date%3A%27%2C%27%27).Trim()). (line 35)

For me the date is at index 3 instead of index 2.

Since my setup is new, I'm not sure if this is an issue specific to my git config, or more tied to the version of Git, or something that is more widely experienced. (I think it has never worked for me, but maybe others have different experience?)

danmetzler commented 2 years ago

One way to check if the issue exists on a system:

$log = git --no-pager log -q --grep '^AU: ' --date iso --all | out-string
$all_commits = $log | Select-String 'commit(.|\n)+?(?=\ncommit )' -AllMatches
$ind = 0
foreach ($commit in $all_commits.Matches.Value) {
     $commit = $commit -split '\n'
     $date     = $commit[2].Replace('Date:','').Trim()
     "Index: $ind, Date: $date"
     $ind++
 }

If a non-date shows up for the date, the issue is there.

danmetzler commented 2 years ago

On further investigation this happens with a merge commit. In that scenario, the next line after the commit line is of the format Merge: <ref> <ref>. Then author and date are shifted down one to the 3rd and 4th lines. This is because I did some work in another branch, and then merged into the main branch.

majkinetor commented 2 years ago

Ah, that must be it, we don't have merges with described AppVeyor system so that setup was never taken into consideration.

danmetzler commented 2 years ago

It seems to me there are a couple of approaches we could take to fix:

If we want to do the second option, I think we could look at the commit line that normally contains "Date:" and if it doesn't contain "Date:" then assume it is a merge commit and don't include it.

Any thoughts?

majkinetor commented 2 years ago

Lets just add --no-merges param to git log and call it a day.

danmetzler commented 2 years ago

Lets just add --no-merges param to git log and call it a day.

Perfect!