-
Notifications
You must be signed in to change notification settings - Fork 29
/
Get-GitFileMetadata.ps1
60 lines (53 loc) · 1.59 KB
/
Get-GitFileMetadata.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<#
.SYNOPSIS
Returns the creation and last modification metadata for a file in a git repo.
.FUNCTIONALITY
Git and GitHub
.LINK
Use-Command.ps1
.LINK
Get-ChildItem
.LINK
Resolve-Path
.EXAMPLE
Get-GitFileMetadata.ps1 README.md
Path : .\README.md
CreateCommit : 1fde7af
CreateAuthor : Brian Lalonde
CreateEmail : [email protected]
CreateDate : 01/19/2015 11:44:15
LastCommit : dbe27ba
LastAuthor : Brian Lalonde
LastEmail : [email protected]
LastDate : 12/07/2020 20:17:15
#>
#Requires -Version 3
[CmdletBinding()][OutputType([psobject])] Param(
# The path (or paths) to get metadata for.
[Parameter(Position=0,Mandatory=$true,ValueFromPipelineByPropertyName=$true,ValueFromRemainingArguments=$true)]
[string[]] $Path,
# Recurse into subdirectories.
[switch] $Recurse
)
Begin { Use-Command.ps1 git "$env:ProgramFiles\Git\cmd\git.exe" -choco git }
Process
{
foreach($f in Get-ChildItem $Path -Recurse:$Recurse)
{
$create_commit,$create_author,$create_email,$create_date =
(git log --reverse --format="%h%x09%cn%x09%ae%x09%ai" $f |Select-Object -f 1) -split '\t'
$last_commit,$last_author,$last_email,$last_date =
(git log -1 --format="%h%x09%cn%x09%ae%x09%ai" $f |Select-Object -f 1) -split '\t'
[pscustomobject]@{
Path = Resolve-Path $f -Relative
CreateCommit = $create_commit
CreateAuthor = $create_author
CreateEmail = $create_email
CreateDate = [datetime]$create_date
LastCommit = $last_commit
LastAuthor = $last_author
LastEmail = $last_email
LastDate = [datetime]$last_date
}
}
}