ugit.types.ps1xml
<?xml version="1.0" encoding="utf-16"?> <!-- Generated with EZOut 2.0.6: Install-Module EZOut or https://github.com/StartAutomating/EZOut --> <Types> <Type> <Name>git.blame</Name> <Members> <ScriptProperty> <Name>Log</Name> <GetScriptBlock> Push-Location $this.GitRoot git log $this.CommitHash -NumberOfCommits 1 Pop-Location </GetScriptBlock> </ScriptProperty> </Members> </Type> <Type> <Name>git.branch</Name> <Members> <AliasProperty> <Name>Compare</Name> <ReferencedMemberName>Diff</ReferencedMemberName> </AliasProperty> <AliasProperty> <Name>HasUpstream</Name> <ReferencedMemberName>IsTracked</ReferencedMemberName> </AliasProperty> <ScriptMethod> <Name>Delete</Name> <Script> Push-Location $this.GitRoot git branch '-d' $this.BranchName @args Pop-Location </Script> </ScriptMethod> <ScriptMethod> <Name>Diff</Name> <Script> param() $firstArg, $restOfArgs = if (-not $args) { git remote | git remote show | Select-Object -ExpandProperty HeadBranch -First 1 } else { $args | Select-Object -First 1 $args | Select-Object -Skip 1 } $restOfArgs = @($restOfArgs) Push-Location $this.GitRoot git diff "$($firstArg)..$($this.BranchName)" @restOfArgs Pop-Location </Script> </ScriptMethod> <ScriptMethod> <Name>Rename</Name> <Script> if (-not $args) { throw "Must provide a new branch name" } Push-Location $this.GitRoot git branch '-m' $this.BranchName @args Pop-Location </Script> </ScriptMethod> <ScriptMethod> <Name>ToString</Name> <Script> $this.BranchName </Script> </ScriptMethod> <ScriptProperty> <Name>IsTracked</Name> <GetScriptBlock> Push-Location $this.GitRoot ( git remote | git remote show | Select-Object -ExpandProperty RemoteBranches | Where-Object BranchName -like "*$($this.BranchName)" ) -as [bool] Pop-Location </GetScriptBlock> </ScriptProperty> </Members> </Type> <Type> <Name>git.branch.detail</Name> <Members> <ScriptMethod> <Name>Delete</Name> <Script> Push-Location $this.GitRoot git branch '-d' $this.BranchName @args Pop-Location </Script> </ScriptMethod> <ScriptMethod> <Name>ToString</Name> <Script> $this.BranchName </Script> </ScriptMethod> </Members> </Type> <Type> <Name>git.checkout</Name> <Members> </Members> </Type> <Type> <Name>git.clone</Name> <Members> <ScriptMethod> <Name>ToString</Name> <Script> $this.Directory.ToString() </Script> </ScriptMethod> </Members> </Type> <Type> <Name>git.commit.info</Name> <Members> <ScriptMethod> <Name>Amend</Name> <Script> param( [Parameter(Mandatory)] [string] $Message ) Push-Location $this.GitRoot git commit --ammend -m $Message @args Pop-Location </Script> </ScriptMethod> <ScriptMethod> <Name>Push</Name> <Script> Push-Location $this.GitRoot git push @args Pop-Location </Script> </ScriptMethod> <ScriptMethod> <Name>UpdateMessage</Name> <Script> param( [Parameter(Mandatory)] [string] $Message ) Push-Location $this.GitRoot git commit --ammend -m $Message @args Pop-Location </Script> </ScriptMethod> </Members> </Type> <Type> <Name>git.diff</Name> <Members> </Members> </Type> <Type> <Name>git.error</Name> <Members> <ScriptProperty> <Name>UnknownRevision</Name> <GetScriptBlock> <# .SYNOPSIS Gets Unknown Revisions .DESCRIPTION Gets Unknown Revisions from any git error output. #> if ($this -match "'(?<n>.+?)'\: unknown revision or path not in the working tree") { $matches.n } </GetScriptBlock> </ScriptProperty> </Members> </Type> <Type> <Name>git.grep</Name> <Members> </Members> </Type> <Type> <Name>git.init</Name> <Members> </Members> </Type> <Type> <Name>git.log</Name> <Members> <AliasProperty> <Name>Changes</Name> <ReferencedMemberName>Change</ReferencedMemberName> </AliasProperty> <AliasProperty> <Name>Date</Name> <ReferencedMemberName>CommitDate</ReferencedMemberName> </AliasProperty> <AliasProperty> <Name>JiraTickets</Name> <ReferencedMemberName>JiraTicket</ReferencedMemberName> </AliasProperty> <AliasProperty> <Name>Trailers</Name> <ReferencedMemberName>Trailer</ReferencedMemberName> </AliasProperty> <AliasProperty> <Name>UserName</Name> <ReferencedMemberName>GitUserName</ReferencedMemberName> </AliasProperty> <ScriptMethod> <Name>Archive</Name> <Script> param( [Parameter(Mandatory)] [string] $ArchivePath ) $unresolvedArchivePath = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($ArchivePath) Push-Location $this.GitRoot git archive $this.CommitHash '-o' "$unresolvedArchivePath" @args Pop-Location </Script> </ScriptMethod> <ScriptMethod> <Name>Checkout</Name> <Script> Push-Location $this.GitRoot git checkout $this.CommitHash @args Pop-Location </Script> </ScriptMethod> <ScriptMethod> <Name>Diff</Name> <Script> Push-Location $this.GitRoot $logPaths = @($this.GitCommand -split '\s' -notmatch '^(?>git|log)$' -notmatch '^\-' -ne '') Write-Debug "Logging paths: $logPaths" foreach ($logPath in $logPaths) { if (Test-Path $logPath) { $relativeArgs = @("--relative", $logPath) git diff $this.CommitHash @relativeArgs @args } } if (-not $logPaths) { Write-Debug "Getting diff of commit hash: $($this.CommitHash)" git diff $this.CommitHash @args } Pop-Location </Script> </ScriptMethod> <ScriptMethod> <Name>GetNote</Name> <Script> <# .SYNOPSIS Gets git commit notes .DESCRIPTION Gets git notes associated with a commit. #> $pushed = if ($this.GitRoot -ne $pwd) { Push-Location $this.GitRoot $true } else { $false } $showNotes = git notes show $this.CommitHash *>&1 if ($showNotes -isnot [Management.Automation.ErrorRecord]) { $showNotes } else { $error.RemoveAt(0) } if ($pushed) { Pop-Location } </Script> </ScriptMethod> <ScriptMethod> <Name>Reset</Name> <Script> Push-Location $this.GitRoot git reset $this.CommitHash @args Pop-Location </Script> </ScriptMethod> <ScriptMethod> <Name>Revert</Name> <Script> Push-Location $this.GitRoot git revert $this.CommitHash @args Pop-Location </Script> </ScriptMethod> <ScriptProperty> <Name>Change</Name> <GetScriptBlock> <# .SYNOPSIS Gets the changes in a git commit .DESCRIPTION Gets the changes in a git commit. This function is used to get the changes in a git commit. The changes are returned as a PSCustomObject with the following properties: - FilePath: The path of the file that was changed - LinesChanged: The number of lines changed in the file - LinesInserted: The number of lines inserted in the file - LinesDeleted: The number of lines deleted in the file #> return @(foreach ($outLine in $this.GitOutputLines) { if ($outLine -notlike ' *|*') { continue } $nameOfFile, $fileChanges = $outLine -split '\|' $nameOfFile = $nameOfFile -replace '^\s+' -replace '\s+$' $match = [Regex]::Match($fileChanges, "(?<c>\d+)\s(?<i>\+{0,})(?<d>\-{0,})") $linesChanged = $match.Groups["c"].Value -as [int] $linesInserted = $match.Groups["i"].Length $linesDeleted = $match.Groups["d"].Length [PSCustomObject][Ordered]@{ PSTypeName = 'git.log.change' FilePath = $nameOfFile LinesChanged = $linesChanged LinesInserted = $linesInserted LinesDeleted = $linesDeleted } }) </GetScriptBlock> </ScriptProperty> <ScriptProperty> <Name>CommitDate</Name> <GetScriptBlock> <# .SYNOPSIS Gets the date of a git log .DESCRIPTION Gets the commit date of a git log entry. #> return [datetime]::ParseExact($this.CommitDateString.Trim(), "ddd MMM d HH:mm:ss yyyy K", [cultureinfo]::InvariantCulture) </GetScriptBlock> </ScriptProperty> <ScriptProperty> <Name>CommitType</Name> <GetScriptBlock> <# .SYNOPSIS Gets the type of a conventional commit .DESCRIPTION Gets the type of a conventional commit, based on the commit message. #> if ($this.CommitMessage -match '^(?<Type>[^\r\n]+?):\s{0,}(?<Message>[^\r\n]+)') { $matchType = $Matches.Type if ($matchType -match '\(') { $matchType -replace '\(.+$' } else { $matchType } } else { return '' } </GetScriptBlock> </ScriptProperty> <ScriptProperty> <Name>Description</Name> <GetScriptBlock> <# .SYNOPSIS Gets the description of a commit .DESCRIPTION Gets the description of a conventional commit, or the first line of the commit message. .LINK https://www.conventionalcommits.org/en/v1.0.0/#summary #> if ($this.CommitMessage -match '^(?<Type>[^\r\n]+?):\s{0,}(?<Message>[^\r\n]+)') { return $Matches.Message } else { $firstLine, $null = $this.CommitMessage -split '(?>\r\n|\n)' return $firstLine } </GetScriptBlock> </ScriptProperty> <ScriptProperty> <Name>JiraTicket</Name> <GetScriptBlock> <# .SYNOPSIS Extracts Jira ticket numbers from commit messages. .DESCRIPTION Extracts Jira ticket numbers from commit messages. Returns a list of objects with the ProjectName and TicketNumber properties. .EXAMPLE # Get the Jira ticket information from the current branch. git log -CurrentBranch | Where-Object JiraTicket #> foreach ($match in [Regex]::new("(?<ProjectName>\S+)-(?<TicketNumber>\d+)").Matches($this.CommitMessage)) { [PSCustomObject][Ordered]@{ ProjectName = $match.Groups['ProjectName'].Value TicketNumber = [int]$match.Groups['TicketNumber'].Value } } </GetScriptBlock> </ScriptProperty> <ScriptProperty> <Name>ReferenceNumbers</Name> <GetScriptBlock> [Regex]::new("#(?<n>\d+)").Matches($this.CommitMessage) -replace '#' -as [int[]] </GetScriptBlock> </ScriptProperty> <ScriptProperty> <Name>Scope</Name> <GetScriptBlock> <# .SYNOPSIS Gets the scope of a conventional commit .DESCRIPTION Gets the scope of a conventional commit, based on the commit message. .LINK https://www.conventionalcommits.org/en/v1.0.0/#summary #> if ($this.CommitMessage -match '^(?<Type>[^\r\n]+?):\s{0,}(?<Message>[^\r\n]+)') { $matchType = $Matches.Type if ($matchType -match '\(') { $matchType -replace '.+?\(' -replace '\)\s{0,}$' } else { return '' } } else { return '' } </GetScriptBlock> </ScriptProperty> <ScriptProperty> <Name>Trailer</Name> <GetScriptBlock> <# .SYNOPSIS Gets the trailer of a commit .DESCRIPTION Gets the trailers of a commit. Git trailers are key-value pairs that are appended to the end of a commit message. .LINK https://git-scm.com/docs/git-interpret-trailers #> $lineNumber = 0 $gitTrailers = [Ordered]@{} foreach ($commitMessageLine in $this.CommitMessage -split '(?>\r\n|\n)') { $lineNumber++ if ($commitMessageLine -notmatch '\s{0,}(?<k>\S+):\s(?<v>[\s\S]+$)' -or $lineNumber -eq 1) { continue } if (-not $gitTrailers[$matches.k]) { $gitTrailers[$matches.k] = $matches.v } else { $gitTrailers[$matches.k] = @($gitTrailers[$matches.k]) + $v } } return $gitTrailers </GetScriptBlock> </ScriptProperty> </Members> </Type> <Type> <Name>git.merge.error</Name> <Members> <ScriptProperty> <Name>Conflict</Name> <GetScriptBlock> <# .SYNOPSIS Gets Conflicts .DESCRIPTION Gets Conflicts from any git merge output. #> foreach ($line in $this -split '[\r\n]+') { if ($line -match "^\t(?<path>.+?)\s{0,}$") { $matches.path } } </GetScriptBlock> </ScriptProperty> </Members> </Type> <Type> <Name>git.output</Name> <Members> <ScriptProperty> <Name>NotGitCommand</Name> <GetScriptBlock> <# .SYNOPSIS Gets what was not a Git Command .DESCRIPTION If the git output is not a git command, this will output the command name. #> if ($this -match "^git:\s'(?<cmd>.+?)' is not a git command.") { return $matches.cmd } </GetScriptBlock> </ScriptProperty> </Members> </Type> <Type> <Name>git.pull</Name> <Members> </Members> </Type> <Type> <Name>git.pull.error</Name> <Members> <ScriptProperty> <Name>Conflict</Name> <GetScriptBlock> <# .SYNOPSIS Gets Conflicts .DESCRIPTION Gets Conflicts from any git pull output. #> foreach ($line in $this -split '[\r\n]+') { if ($line -match "^\t(?<path>.+?)\s{0,}$") { $matches.path } } </GetScriptBlock> </ScriptProperty> </Members> </Type> <Type> <Name>git.push</Name> <Members> </Members> </Type> <Type> <Name>git.reference.log</Name> <Members> <AliasProperty> <Name>CommitHash</Name> <ReferencedMemberName>Hash</ReferencedMemberName> </AliasProperty> <ScriptMethod> <Name>Archive</Name> <Script> param( [Parameter(Mandatory)] [string] $ArchivePath ) $unresolvedArchivePath = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($ArchivePath) Push-Location $this.GitRoot git archive $this.CommitHash '-o' "$unresolvedArchivePath" @args Pop-Location </Script> </ScriptMethod> <ScriptMethod> <Name>Checkout</Name> <Script> Push-Location $this.GitRoot git checkout $this.CommitHash @args Pop-Location </Script> </ScriptMethod> <ScriptMethod> <Name>Diff</Name> <Script> Push-Location $this.GitRoot git diff $this.CommitHash @args Pop-Location </Script> </ScriptMethod> <ScriptMethod> <Name>Reset</Name> <Script> Push-Location $this.GitRoot git reset $this.CommitHash @args Pop-Location </Script> </ScriptMethod> <ScriptMethod> <Name>Revert</Name> <Script> Push-Location $this.GitRoot git revert $this.CommitHash @args Pop-Location </Script> </ScriptMethod> <ScriptProperty> <Name>ReferenceNumbers</Name> <GetScriptBlock> [Regex]::new("#(?<n>\d+)").Matches($this.CommitMessage) -replace '#' -as [int[]] </GetScriptBlock> </ScriptProperty> </Members> </Type> <Type> <Name>git.remote</Name> <Members> </Members> </Type> <Type> <Name>git.remote.name</Name> <Members> <ScriptMethod> <Name>ToString</Name> <Script> "$($this.RemoteName)" </Script> </ScriptMethod> </Members> </Type> <Type> <Name>git.removal</Name> <Members> </Members> </Type> <Type> <Name>git.shortlog</Name> <Members> </Members> </Type> <Type> <Name>git.stash</Name> <Members> </Members> </Type> <Type> <Name>git.stash.entry</Name> <Members> <ScriptMethod> <Name>Apply</Name> <Script> Push-Location $this.GitRoot git stash apply $this.Number Pop-Location </Script> </ScriptMethod> <ScriptMethod> <Name>Delete</Name> <Script> Push-Location $this.GitRoot git stash drop $this.Number Pop-Location </Script> </ScriptMethod> <ScriptMethod> <Name>Diff</Name> <Script> Push-Location $this.GitRoot git stash show $this.Number --patch Pop-Location </Script> </ScriptMethod> <ScriptMethod> <Name>Drop</Name> <Script> Push-Location $this.GitRoot git stash drop $this.Number Pop-Location </Script> </ScriptMethod> <ScriptMethod> <Name>Pop</Name> <Script> Push-Location $this.GitRoot git stash pop $this.Number Pop-Location </Script> </ScriptMethod> </Members> </Type> <Type> <Name>git.status</Name> <Members> <ScriptMethod> <Name>Push</Name> <Script> Push-Location $this.GitRoot if (-not $this.Status) { git push --set-upstream origin $this.BranchName @args } else { git push @args } Pop-Location </Script> </ScriptMethod> </Members> </Type> <Type> <Name>git.submodule</Name> <Members> </Members> </Type> <Type> <Name>System.IO.FileInfo</Name> <Members> <AliasProperty> <Name>Changes</Name> <ReferencedMemberName>GitChanges</ReferencedMemberName> </AliasProperty> <AliasProperty> <Name>Diff</Name> <ReferencedMemberName>GitDiff</ReferencedMemberName> </AliasProperty> <AliasProperty> <Name>GitDifference</Name> <ReferencedMemberName>GitDiff</ReferencedMemberName> </AliasProperty> <AliasProperty> <Name>GitHistory</Name> <ReferencedMemberName>GitChanges</ReferencedMemberName> </AliasProperty> <AliasProperty> <Name>GitLog</Name> <ReferencedMemberName>GitLogs</ReferencedMemberName> </AliasProperty> <AliasProperty> <Name>HasChanged</Name> <ReferencedMemberName>GitDirty</ReferencedMemberName> </AliasProperty> <AliasProperty> <Name>HasChanges</Name> <ReferencedMemberName>GitDirty</ReferencedMemberName> </AliasProperty> <AliasProperty> <Name>History</Name> <ReferencedMemberName>GitChanges</ReferencedMemberName> </AliasProperty> <AliasProperty> <Name>IsUnstaged</Name> <ReferencedMemberName>GitDirty</ReferencedMemberName> </AliasProperty> <AliasProperty> <Name>Logs</Name> <ReferencedMemberName>GitLogs</ReferencedMemberName> </AliasProperty> <ScriptMethod> <Name>GitChanges</Name> <Script> <# .SYNOPSIS Get Changes for a given file .DESCRIPTION Gets changes from git for a given file. Can provide a timespan, series of numbers, date, or pair of dates. #> $byDate = @() $byNumber = @() $byTimespan = @() foreach ($arg in $args) { if ($arg -as [int] -ne $null) { $byNumber += $arg -as [int] } elseif ($arg -is [object[]]) { $byNumber += $arg } elseif ($arg -as [DateTime]) { $byDate+= $arg -as [DateTime] } elseif ( $arg -as [TimeSpan] ) { $byTimespan+= $arg -as [TimeSpan] } } Push-Location $this.Directory if ($byTimespan) { git log -Since ([DateTime]::Now - $byTimespan[0]) $this.Name } elseif ($byDate) { if ($byDate.Length -gt 1) { $first, $second = $byDate | Sort-Object git log -After $second -Before $first $this.Name } elseif ($byDate.Length -eq 1) { git log -Since $byDate[0] $this.Name } else { throw "Can only list Changes between two dates" } } elseif ($byNumber.Length) { $maxNumber = $byNumber | Measure-Object -Maximum | Select-Object -ExpandProperty Maximum $maxNumber = $maxNumber + 1 $anyNegative = @($byNumber -lt 0).Length if ($anyNegative) { @(git log $this.Name)[@($byNumber -as [int[]])] } else { @(git log -n $maxNumber $this.Name)[@($byNumber -as [int[]])] } } else { git log $this.Name } Pop-Location </Script> </ScriptMethod> <ScriptProperty> <Name>GitDiff</Name> <GetScriptBlock> Push-Location $this.Directory (git log -n 1 $this.Name).Diff() Pop-Location </GetScriptBlock> </ScriptProperty> <ScriptProperty> <Name>GitDirty</Name> <GetScriptBlock> Push-Location $this.Directory $(git status $this.Name '-s') -as [bool] Pop-Location </GetScriptBlock> </ScriptProperty> <ScriptProperty> <Name>GitLogs</Name> <GetScriptBlock> Push-Location $this.Directory git log $this.Name Pop-Location </GetScriptBlock> </ScriptProperty> </Members> </Type> <Type> <Name>ugit</Name> <Members> <AliasProperty> <Name>ConventionalCommits</Name> <ReferencedMemberName>ConventionalCommit</ReferencedMemberName> </AliasProperty> <ScriptProperty> <Name>ConventionalCommit</Name> <GetScriptBlock> if (-not $this.'.ConventionalCommits') { $this | Add-Member NoteProperty '.ConventionalCommits' ([PSCustomObject]@{ PSTypeName = 'ugit.Conventional.Commit' }) } $this.'.ConventionalCommits' </GetScriptBlock> </ScriptProperty> </Members> </Type> <Type> <Name>ugit.Conventional.Commit</Name> <Members> <AliasProperty> <Name>Types</Name> <ReferencedMemberName>Type</ReferencedMemberName> </AliasProperty> <ScriptProperty> <Name>Type</Name> <GetScriptBlock> <# .SYNOPSIS Gets Conventional Commit Types .DESCRIPTION Gets the different types of Conventional Commits .EXAMPLE $ugit.ConventionalCommit.Type .LINK https://www.conventionalcommits.org/en/v1.0.0/#specification #> param() if (-not $this.'.Types') { $this | Add-Member NoteProperty '.Types' @( "feat" # feature "fix" # bugfix "build" # build related "chore" # chore / code housekeeping "ci" # ci "docs" # documentation "style" # stylistic "refactor" # refactoring "release" # releasing "perf" # performance improvement "test" # tests "BREAKING CHANGE" # BREAKING CHANGES ) -Force } $this.'.Types' </GetScriptBlock> <SetScriptBlock> param() $unrolledArgs = @($args | . { process { $_ }}) $standardTypes = @( "feat" # feature "fix" # bugfix "build" # build related "chore" # chore / code housekeeping "ci" # ci "docs" # documentation "style" # stylistic "refactor" # refactoring "release" # releasing "perf" # performance improvement "test" # tests "BREAKING CHANGE" # BREAKING CHANGES ) $combinedTypes = @(@($unrolledArgs + $standardTypes) | Select-Object -Unique) $this | Add-Member NoteProperty '.Types' $combinedTypes -Force </SetScriptBlock> </ScriptProperty> <NoteProperty> <Name>README</Name> <Value>Conventional Commits are a useful way to organize your commit messages in Git. To learn more about them, visit: https://www.conventionalcommits.org/ ugit makes them a little easier to work with. In ugit, `git commit` supports a virtual parameter `-Type`. You can tab thru any conventional commit types until you find the right one.</Value> </NoteProperty> </Members> </Type> <Type> <Name>ugit.extension</Name> <Members> <ScriptProperty> <Name>Pattern</Name> <GetScriptBlock> foreach ($attr in $this.ScriptBlock.Attributes) { if ($attr -is [Management.Automation.ValidatePatternAttribute]) { $attr.RegexPattern } } </GetScriptBlock> </ScriptProperty> </Members> </Type> </Types> |