8000 WIP - More work on Get-GitVersion · PoshCode/PSGit@5378d31 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5378d31

Browse files
committed
WIP - More work on Get-GitVersion
1 parent e16be5f commit 5378d31

File tree

2 files changed

+44
-37
lines changed

2 files changed

+44
-37
lines changed

Examples/TestVersions.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,5 +176,5 @@ Test-Version $NewVersion
176176
## MERGE TO MASTER
177177
$NewVersion = "18.6.7"
178178
git checkout master
179-
git merge --no-ff -m "Want $NewVersion (merge $NewVersion)" releases/$NewVersion
179+
git merge --no-ff -m "Want $NewVersion (merge $NewVersion)" releases/18.6.6
180180
Test-Version $NewVersion

Get-GitVersion.ps1

Lines changed: 43 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,45 +6,52 @@ enum Part {
66
None
77
}
88

9-
function Get-Log {
10-
[CmdletBinding()]
11-
param()
12-
# # We have to transform the object to keep the data around after .Dispose()
13-
$Branches = $repo.Branches | Select-Object CanonicalName, FriendlyName, Is*, RemoteName, Tip, Track*, Upstream*, Ahead, Behind
14-
15-
$Tags = @($repo.Tags)
16-
$Log = $repo.Commits | Select-Object Id,
17-
@{name = "Branch"; expr = { $c = $_; $Branches.Where{$c.Id -eq $_.Tip.Id} }},
18-
@{name = "Tags"; expr = { $c = $_; $Tags.Where{$c.Id -eq $_.Target.Id} }},
19-
Parents, Author,
20-
@{name = "Date"; expr = { $_.Author.When}},
21-
@{name = "Message"; expr = { $_.MessageShort}} |
22-
ForEach-Object { $_.PSTypeNames.Insert(0, "PSGit.Commit"), $_ }
23-
24-
# Make the branch tip be one of the objects in the Log
25-
foreach ($branch in $Branches) {
26-
$branch.Tip = $Log.Where( {$_.Id -eq $branch.Tip.Id}, 1)
27-
}
9+
function Get-Log {
10+
[CmdletBinding()]
11+
param()
12+
# # We have to transform the object to keep the data around after .Dispose()
13+
$Branches = $repo.Branches | Select-Object CanonicalName, FriendlyName, Is*,
14+
RemoteName, Tip, Track*, Upstream*, Ahead, Behind,
15+
@{name = "IsMerged"; expr = { $false } }
16+
17+
$Tags = @($repo.Tags)
18+
$Log = $repo.Commits | Select-Object Id,
19+
@{name = "Branch"; expr = { $c = $_; $Branches.Where({$c.Id -eq $_.Tip.Id},1) }},
20+
@{name = "Tags"; expr = { $c = $_; $Tags.Where{$c.Id -eq $_.Target.Id} }},
21+
Parents, Author,
22+
@{name = "Date"; expr = { $_.Author.When}},
23+
@{name = "Message"; expr = { $_.MessageShort}} |
24+
ForEach-Object { $_.PSTypeNames.Insert(0, "PSGit.Commit"), $_ }
25+
26+
# Make the branch tip be one of the objects in the Log
27+
foreach ($branch in $Branches) {
28+
if($tip = $Log.Where( {$_.Id -eq $branch.Tip.Id}, 1)) {
29+
$branch.Tip = $tip
30+
}
31+
}
2832

29-
# We need to fix:
30-
# - only the tips of each branch have branch data
31-
# - the parent commit objects are separate (but identical) objects
32-
foreach ($commit in $Log) {
33-
Write-Verbose "Commit $($commit.Id) Branch: $($commit.Branch.FriendlyName)"
34-
# Reset the "Parents" to be pointers to their representation in the Log
35-
$commit.Parents = $Log.Where{$_.Id -in $commit.Parents.Id}
36-
# Set the branch on all the parents
37-
foreach ($parent in $commit.Parents) {
38-
# How do we pick which "branch" a merge commit is in?
39-
if (!$parent.Branch) {
40-
# Write-Verbose "+ Update $($parent.Id) Branch: $($commit.Branch.FriendlyName)"
41-
$parent.Branch = $commit.Branch
42-
}
43-
}
33+
# We need to fix:
34+
# - only the tips of each branch have branch data
35+
# - the parent commit objects are separate (but identical) objects
36+
foreach ($commit in $Log) {
37+
Write-Verbose "Commit $($commit.Id) Branch: $($commit.Branch.FriendlyName)"
38+
# Reset the "Parents" to be pointers to their representation in the Log
39+
$commit.Parents = $Log.Where{$_.Id -in $commit.Parents.Id}
40+
# Set the branch on all the parents
41+
foreach ($parent in $commit.Parents) {
42+
# A merge commit is always in the master branch
43+
if (!$parent.Branch) {
44+
# Write-Verbose "+ Update $($parent.Id) Branch: $($commit.Branch.FriendlyName)"
45+
$parent.Branch = $commit.Branch
46+
} elseif (@($commit.Parents).Count -gt 1 -and $commit.Branch.CanonicalName -ne $parent.Branch.CanonicalName) {
47+
Write-Verbose ($parent.Branch.FriendlyName + " was merged into " + $commit.Branch.FriendlyName)
48+
$parent.Branch.IsMerged = $true
4449
}
45-
46-
Add-Member -Input $Log -Type NoteProperty -Name Branches -Value $Branches -Passthru
4750
}
51+
}
52+
53+
Add-Member -Input $Log -Type NoteProperty -Name Branches -Value $Branches -Passthru
54+
}
4855

4956
function Get-GitVersion {
5057
[CmdletBinding()]

0 commit comments

Comments
 (0)
0