Skip to content

Commit fe99440

Browse files
Merge pull request #69 from StartAutomating/ugitMerges
ugit Merge Improvements
2 parents 451d39b + 80a14b1 commit fe99440

File tree

6 files changed

+114
-12
lines changed

6 files changed

+114
-12
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## 0.2.5:
2+
* Improving .Merged support for git log (#68)
3+
* git log now also returns:
4+
* [int] .PullRequestNumber (the pull request number)
5+
* .Source (the source branch of a merge)
6+
* .Destination (the destination branch of a merge)
7+
---
8+
19
## 0.2.4:
210
* Adding support for git stash (#65)
311
* Allowing git diff extension to display git stash show --patch (#66)

Extensions/Git.Log.UGit.Extension.ps1

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,38 @@
22
.Synopsis
33
Log Extension
44
.Description
5-
Outputs git log entries as objects
5+
Outputs git log as objects.
66
.Example
7-
git log | Group-Object GitUserEmail -NoElement | Sort-Object Count -Descending
8-
.EXAMPLE
9-
git log | Where-Object -Not Merged
10-
.EXAMPLE
11-
git log | Group-Object { $_.CommitDate.DayOfWeek } -NoElement
7+
# Get all logs
8+
git log |
9+
# until the first merged pull request
10+
Where-Object -Not Merged
11+
.Example
12+
# Get a single log entry
13+
git log -n 1 |
14+
# and see what the log object can do.
15+
Get-Member
16+
.Example
17+
# Get all logs
18+
git log |
19+
# Group them by the author
20+
Group-Object GitUserEmail -NoElement |
21+
# sort them by count
22+
Sort-Object Count -Descending
23+
.Example
24+
# Get all logs
25+
git log |
26+
# Group them by day of week
27+
Group-Object { $_.CommitDate.DayOfWeek } -NoElement
28+
.Example
29+
# Get all logs
30+
git log |
31+
# where there is a pull request number
32+
Where-Object PullRequestNumber |
33+
# pick out the PullRequestNumber and CommitDate
34+
Select PullRequestNumber, CommitDate
35+
.Example
36+
git log --merges
1237
#>
1338
[Management.Automation.Cmdlet("Out","Git")] # It's an extension for Out-Git
1439
[ValidatePattern("^git log",Options='IgnoreCase')] # when the pattern is "git log"
@@ -66,9 +91,27 @@ begin {
6691
if ($gitLogOut.CommitMessage) {
6792
$gitLogOut.CommitMessage = $gitLogOut.CommitMessage.Trim()
6893
}
69-
if ($gitLogOut.MergeHash) {
94+
if ($gitLogOut.MergeHash -and
95+
$gitLogOut.CommitMessage -notmatch '^merge branch') {
7096
$script:LogChangesMerged = $true
97+
if ($gitLogOut.CommitMessage -match '^Merge pull request \#(?<Num>\d+)') {
98+
$gitLogOut.PullRequestNumber = [int]$matches.Num
99+
}
100+
if ($gitLogOut.CommitMessage -match 'from[\r\n\s]{0,}(?<Src>\S+)') {
101+
$gitLogOut.Source = $matches.Src
102+
}
103+
}
104+
elseif (
105+
$gitLogOut.MergeHash
106+
) {
107+
if ($gitLogOut.CommitMessage -match "^merge branch '(?<Branch>[^']+)'") {
108+
$gitLogOut.Source = $matches.Branch
109+
}
110+
if ($gitLogOut.CommitMessage -match 'into (?<Branch>.+)$') {
111+
$gitLogOut.Destination = $matches.Branch
112+
}
71113
}
114+
72115
$gitLogOut.Merged = $script:LogChangesMerged
73116
$gitLogOut.GitRoot = $GitRoot
74117
[PSCustomObject]$gitLogOut

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ Get-UGitExtension is built using [Piecemeal](https://github.com/StartAutomating/
7272
* git reflog
7373
* git shortlog
7474
* git status
75+
* git stash
7576

7677
### Extensions that may apply to any git command:
7778

docs/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## 0.2.5:
2+
* Improving .Merged support for git log (#68)
3+
* git log now also returns:
4+
* [int] .PullRequestNumber (the pull request number)
5+
* .Source (the source branch of a merge)
6+
* .Destination (the destination branch of a merge)
7+
---
8+
19
## 0.2.4:
210
* Adding support for git stash (#65)
311
* Allowing git diff extension to display git stash show --patch (#66)

docs/Git.Log-Extension.md

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,57 @@ Log Extension
77
---
88
### Description
99

10-
Outputs git log entries as objects
10+
Outputs git log as objects.
1111

1212
---
1313
### Examples
1414
#### EXAMPLE 1
1515
```PowerShell
16-
git log | Group-Object GitUserEmail -NoElement | Sort-Object Count -Descending
16+
# Get all logs
17+
git log |
18+
# until the first merged pull request
19+
Where-Object -Not Merged
1720
```
1821

1922
#### EXAMPLE 2
2023
```PowerShell
21-
git log | Where-Object -Not Merged
24+
# Get a single log entry
25+
git log -n 1 |
26+
# and see what the log object can do.
27+
Get-Member
2228
```
2329

2430
#### EXAMPLE 3
2531
```PowerShell
26-
git log | Group-Object { $_.CommitDate.DayOfWeek } -NoElement
32+
# Get all logs
33+
git log |
34+
# Group them by the author
35+
Group-Object GitUserEmail -NoElement |
36+
# sort them by count
37+
Sort-Object Count -Descending
38+
```
39+
40+
#### EXAMPLE 4
41+
```PowerShell
42+
# Get all logs
43+
git log |
44+
# Group them by day of week
45+
Group-Object { $_.CommitDate.DayOfWeek } -NoElement
46+
```
47+
48+
#### EXAMPLE 5
49+
```PowerShell
50+
# Get all logs
51+
git log |
52+
# where there is a pull request number
53+
Where-Object PullRequestNumber |
54+
# pick out the PullRequestNumber and CommitDate
55+
Select PullRequestNumber, CommitDate
56+
```
57+
58+
#### EXAMPLE 6
59+
```PowerShell
60+
git log --merges
2761
```
2862

2963
---

ugit.psd1

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@{
2-
ModuleVersion = '0.2.4'
2+
ModuleVersion = '0.2.5'
33
RootModule = 'ugit.psm1'
44
FormatsToProcess = 'ugit.format.ps1xml'
55
TypesToProcess = 'ugit.types.ps1xml'
@@ -16,6 +16,14 @@ PrivateData = @{
1616
ProjectURI = 'https://github.com/StartAutomating/ugit'
1717
LicenseURI = 'https://github.com/StartAutomating/ugit/blob/main/LICENSE'
1818
ReleaseNotes = @'
19+
## 0.2.5:
20+
* Improving .Merged support for git log (#68)
21+
* git log now also returns:
22+
* [int] .PullRequestNumber (the pull request number)
23+
* .Source (the source branch of a merge)
24+
* .Destination (the destination branch of a merge)
25+
---
26+
1927
## 0.2.4:
2028
* Adding support for git stash (#65)
2129
* Allowing git diff extension to display git stash show --patch (#66)

0 commit comments

Comments
 (0)