Last active
March 29, 2019 12:50
-
-
Save michaelkc/7dd3ff95d792dd859e5453b2f8547596 to your computer and use it in GitHub Desktop.
List my git commits in the last two months, made to any repo in subfolder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#https://gist.github.com/michaelkc/7dd3ff95d792dd859e5453b2f8547596/#file-my_git_commits-ps1 | |
Set-StrictMode -Version Latest | |
$git = "C:\Program Files\Git\bin\git.exe" | |
function Find-GitRepos($root) | |
{ | |
$blacklist = @("node_modules") | |
$isGitRepo = Get-ChildItem $root -Hidden -Directory | Where-Object {$_.Name -eq ".git"} | |
if ($isGitRepo) | |
{ | |
return @($root) | |
} | |
else | |
{ | |
$gitRepos = @() | |
$childDirs = Get-ChildItem $root -Directory -Exclude $blacklist | |
foreach ($dir in $childDirs) | |
{ | |
$gitRepos = $gitRepos + (Find-GitRepos $dir) | |
} | |
return $gitRepos | |
} | |
} | |
function Get-MyCommits($root) | |
{ | |
$repo = $root.Name | |
$myname = &$git config --get user.name | |
$commitsByMe = (&$git log --since='last 2 months' --author="$myname" --pretty=format:"SPLITME%ai%n%B%b%H" --shortstat --no-merges)|Out-String | |
$commits = ($commitsByMe -split "SPLITME") | Where-Object {$_} | |
foreach ($commit in $commits) | |
{ | |
$lines = ($commit -split "`n")| Where-Object {([string]$_).trim() -ne ""} | |
$timestamp = $lines[0].Trim() | |
$message = $lines[1].Trim() | |
$sha = $lines[2].Trim() | |
$stats = $lines[3].Trim() | |
$link = [System.Uri]'http://104.131.21.239' | |
New-Object psobject -Property @{ Repo=$repo; Timestamp = $timestamp; Message=$message; Stats=$stats; Commit=$sha; Link=$link; } | |
} | |
} | |
$gitRepos = Find-GitRepos $pwd | |
$allMyCommits = @() | |
foreach ($gitRepo in $gitRepos) | |
{ | |
Push-Location | |
Set-Location ($gitRepo.Fullname) | |
$myCommits = (Get-MyCommits $gitRepo) | |
$allMyCommits = $allMyCommits + $myCommits | |
Pop-Location | |
} | |
$allMyCommits | Sort Commit -Unique| Sort -Desc Timestamp | Out-GridView -Title 'My Git commits' -Wait |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment