Skip to content

Commit

Permalink
Merge pull request #69 from StartAutomating/ugitMerges
Browse files Browse the repository at this point in the history
ugit Merge Improvements
  • Loading branch information
StartAutomating committed Jul 18, 2022
2 parents 451d39b + 80a14b1 commit fe99440
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 12 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 0.2.5:
* Improving .Merged support for git log (#68)
* git log now also returns:
* [int] .PullRequestNumber (the pull request number)
* .Source (the source branch of a merge)
* .Destination (the destination branch of a merge)
---

## 0.2.4:
* Adding support for git stash (#65)
* Allowing git diff extension to display git stash show --patch (#66)
Expand Down
57 changes: 50 additions & 7 deletions Extensions/Git.Log.UGit.Extension.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,38 @@
.Synopsis
Log Extension
.Description
Outputs git log entries as objects
Outputs git log as objects.
.Example
git log | Group-Object GitUserEmail -NoElement | Sort-Object Count -Descending
.EXAMPLE
git log | Where-Object -Not Merged
.EXAMPLE
git log | Group-Object { $_.CommitDate.DayOfWeek } -NoElement
# Get all logs
git log |
# until the first merged pull request
Where-Object -Not Merged
.Example
# Get a single log entry
git log -n 1 |
# and see what the log object can do.
Get-Member
.Example
# Get all logs
git log |
# Group them by the author
Group-Object GitUserEmail -NoElement |
# sort them by count
Sort-Object Count -Descending
.Example
# Get all logs
git log |
# Group them by day of week
Group-Object { $_.CommitDate.DayOfWeek } -NoElement
.Example
# Get all logs
git log |
# where there is a pull request number
Where-Object PullRequestNumber |
# pick out the PullRequestNumber and CommitDate
Select PullRequestNumber, CommitDate
.Example
git log --merges
#>
[Management.Automation.Cmdlet("Out","Git")] # It's an extension for Out-Git
[ValidatePattern("^git log",Options='IgnoreCase')] # when the pattern is "git log"
Expand Down Expand Up @@ -66,9 +91,27 @@ begin {
if ($gitLogOut.CommitMessage) {
$gitLogOut.CommitMessage = $gitLogOut.CommitMessage.Trim()
}
if ($gitLogOut.MergeHash) {
if ($gitLogOut.MergeHash -and
$gitLogOut.CommitMessage -notmatch '^merge branch') {
$script:LogChangesMerged = $true
if ($gitLogOut.CommitMessage -match '^Merge pull request \#(?<Num>\d+)') {
$gitLogOut.PullRequestNumber = [int]$matches.Num
}
if ($gitLogOut.CommitMessage -match 'from[\r\n\s]{0,}(?<Src>\S+)') {
$gitLogOut.Source = $matches.Src
}
}
elseif (
$gitLogOut.MergeHash
) {
if ($gitLogOut.CommitMessage -match "^merge branch '(?<Branch>[^']+)'") {
$gitLogOut.Source = $matches.Branch
}
if ($gitLogOut.CommitMessage -match 'into (?<Branch>.+)$') {
$gitLogOut.Destination = $matches.Branch
}
}

$gitLogOut.Merged = $script:LogChangesMerged
$gitLogOut.GitRoot = $GitRoot
[PSCustomObject]$gitLogOut
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ Get-UGitExtension is built using [Piecemeal](https://github.com/StartAutomating/
* git reflog
* git shortlog
* git status
* git stash

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

Expand Down
8 changes: 8 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 0.2.5:
* Improving .Merged support for git log (#68)
* git log now also returns:
* [int] .PullRequestNumber (the pull request number)
* .Source (the source branch of a merge)
* .Destination (the destination branch of a merge)
---

## 0.2.4:
* Adding support for git stash (#65)
* Allowing git diff extension to display git stash show --patch (#66)
Expand Down
42 changes: 38 additions & 4 deletions docs/Git.Log-Extension.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,57 @@ Log Extension
---
### Description

Outputs git log entries as objects
Outputs git log as objects.

---
### Examples
#### EXAMPLE 1
```PowerShell
git log | Group-Object GitUserEmail -NoElement | Sort-Object Count -Descending
# Get all logs
git log |
# until the first merged pull request
Where-Object -Not Merged
```

#### EXAMPLE 2
```PowerShell
git log | Where-Object -Not Merged
# Get a single log entry
git log -n 1 |
# and see what the log object can do.
Get-Member
```

#### EXAMPLE 3
```PowerShell
git log | Group-Object { $_.CommitDate.DayOfWeek } -NoElement
# Get all logs
git log |
# Group them by the author
Group-Object GitUserEmail -NoElement |
# sort them by count
Sort-Object Count -Descending
```

#### EXAMPLE 4
```PowerShell
# Get all logs
git log |
# Group them by day of week
Group-Object { $_.CommitDate.DayOfWeek } -NoElement
```

#### EXAMPLE 5
```PowerShell
# Get all logs
git log |
# where there is a pull request number
Where-Object PullRequestNumber |
# pick out the PullRequestNumber and CommitDate
Select PullRequestNumber, CommitDate
```

#### EXAMPLE 6
```PowerShell
git log --merges
```

---
Expand Down
10 changes: 9 additions & 1 deletion ugit.psd1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@{
ModuleVersion = '0.2.4'
ModuleVersion = '0.2.5'
RootModule = 'ugit.psm1'
FormatsToProcess = 'ugit.format.ps1xml'
TypesToProcess = 'ugit.types.ps1xml'
Expand All @@ -16,6 +16,14 @@ PrivateData = @{
ProjectURI = 'https://github.com/StartAutomating/ugit'
LicenseURI = 'https://github.com/StartAutomating/ugit/blob/main/LICENSE'
ReleaseNotes = @'
## 0.2.5:
* Improving .Merged support for git log (#68)
* git log now also returns:
* [int] .PullRequestNumber (the pull request number)
* .Source (the source branch of a merge)
* .Destination (the destination branch of a merge)
---
## 0.2.4:
* Adding support for git stash (#65)
* Allowing git diff extension to display git stash show --patch (#66)
Expand Down

0 comments on commit fe99440

Please sign in to comment.