1+ <#
2+ . SYNOPSIS
3+ git log input
4+ . DESCRIPTION
5+ Extends the parameters for git log, making it easier to use from PowerShell.
6+
7+ Allows timeframe parameters to be tab-completed:
8+ * After/Since become --after
9+ * Before/Until become --before
10+ * Author/Committer become --author
11+
12+ Adds -CurrentBranch, which gives the changes between the upstream branch and the current branch.
13+
14+ Also adds -IssueNumber, which searchers for commits that reference particular issues.
15+ . EXAMPLE
16+ git log -CurrentBranch
17+ #>
18+ [ValidatePattern (' ^git log' )]
19+ [Management.Automation.Cmdlet (" Use" , " Git" )]
20+ [CmdletBinding (PositionalBinding = $false )]
21+ param (
22+ # Gets logs after a given date
23+ [DateTime ]
24+ [Alias (' Since' )]
25+ $After ,
26+
27+ # Gets before a given date
28+ [DateTime ]
29+ [Alias (' Until' )]
30+ $Before ,
31+
32+ # Gets lof from a given author or committer
33+ [Alias (' Committer' )]
34+ [string ]
35+ $Author ,
36+
37+ # If set, will get all changes between the upstream branch and the current branch.
38+ [Alias (' UpstreamDelta' , ' ThisBranch' )]
39+ [switch ]
40+ $CurrentBranch ,
41+
42+ # One or more issue numbers. Providing an issue number of 0 will find all log entries that reference an issue.
43+ [Parameter (ValueFromPipelineByPropertyName )]
44+ [Alias (' ReferenceNumbers' , ' ReferenceNumber' , ' IssueNumbers' , ' WorkItemID' , ' WorkItemIDs' )]
45+ [int []]
46+ $IssueNumber
47+ )
48+
49+ foreach ($dashToDoubleDash in ' after' , ' before' , ' author' ) {
50+ if ($PSBoundParameters [$dashToDoubleDash ]) {
51+ " --$dashToDoubleDash "
52+ " $ ( $PSBoundParameters [$dashToDoubleDash ]) "
53+ }
54+ }
55+
56+ if ($CurrentBranch ) {
57+ $headbranch = git remote | git remote show | Select-Object - ExpandProperty HeadBranch
58+ $currentBranchName = git branch | Where-Object IsCurrentBranch
59+ if ($currentBranchName -ne $headbranch ) {
60+ " $headbranch ..$currentBranchName "
61+ } else {
62+ Write-Warning " On $headBranch "
63+ }
64+ }
65+
66+ if ($IssueNumber ) {
67+ " --perl-regexp"
68+ foreach ($IssueNum in $IssueNumber ) {
69+ ' --grep'
70+ if ($IssueNum -eq 0 ) {
71+ ' \#\d+\D'
72+ } else {
73+ " \#$IssueNum \D"
74+ }
75+ }
76+
77+ }
0 commit comments