-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #272 from StartAutomating/ugit-docker
ugit 0.4.4
- Loading branch information
Showing
23 changed files
with
814 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
FROM mcr.microsoft.com/powershell | ||
|
||
RUN apt-get update && apt-get install -y git curl ca-certificates libc6 libgcc1 | ||
|
||
ENV PSModulePath ./Modules | ||
|
||
COPY . ./Modules/ugit | ||
RUN pwsh -c "New-Item -Path /root/.config/powershell/Microsoft.PowerShell_profile.ps1 -Value 'Import-Module ugit' -Force" | ||
RUN apt-get update && apt-get install -y git curl ca-certificates libc6 libgcc1 | ||
|
||
RUN pwsh -c "New-Item -ItemType File -Path \$Profile -Force -Value 'Import-Module ugit'" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<# | ||
.SYNOPSIS | ||
git branch input extension | ||
.DESCRIPTION | ||
Extends the parameters for git branch, making it easier to use from PowerShell. | ||
.EXAMPLE | ||
git branch -Remote | ||
#> | ||
[ValidatePattern('^git branch')] | ||
[Management.Automation.Cmdlet("Use","Git")] | ||
[CmdletBinding(PositionalBinding=$false)] | ||
param( | ||
# If set, will add the --remote flag to the command. | ||
[Parameter(ValueFromPipelineByPropertyName)] | ||
[Alias('Remotes')] | ||
[switch] | ||
$Remote | ||
) | ||
|
||
if ($Remote) { | ||
"--remote" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
<# | ||
.SYNOPSIS | ||
git checkout input extension | ||
.DESCRIPTION | ||
Extends the parameters for git checkout, making it easier to use from PowerShell. | ||
If the -PullRequest parameter is provided, the branch will be fetched from the remote. | ||
If the -BranchName parameter is provided, the branch will be checked out. | ||
#> | ||
[ValidatePattern('^git checkout')] | ||
[Management.Automation.Cmdlet("Use","Git")] | ||
[CmdletBinding(PositionalBinding=$false)] | ||
param( | ||
# The branch name. | ||
[Parameter(ValueFromPipelineByPropertyName)] | ||
[string] | ||
$BranchName, | ||
|
||
# The number of the pull request. | ||
# If no Branch Name is provided, the branch will be `PR-$PullRequest`. | ||
[Parameter(ValueFromPipelineByPropertyName)] | ||
[int] | ||
$PullRequest, | ||
|
||
# The name of a new branch | ||
[Parameter(ValueFromPipelineByPropertyName)] | ||
[Alias('New','NewBranch')] | ||
[string] | ||
$NewBranchName, | ||
|
||
# The name of a branch to reset. | ||
[Parameter(ValueFromPipelineByPropertyName)] | ||
[Alias('ResetBranch')] | ||
[string] | ||
$ResetBranchName, | ||
|
||
# One or more specific paths to reset. | ||
# This will overwrite the contents of the files with the contents of the index. | ||
[Parameter(ValueFromPipelineByPropertyName)] | ||
[Alias('Reset')] | ||
[string[]] | ||
$ResetPath, | ||
|
||
# The name of the branch to checkout from. | ||
# This is only used when the -ResetPath parameter is provided. | ||
# It defaults to `HEAD`. | ||
[Parameter(ValueFromPipelineByPropertyName)] | ||
[string] | ||
$FromBranch = 'HEAD', | ||
|
||
# The revision number to checkout. | ||
# This is only used when the -ResetPath parameter is provided. | ||
# If provided, this will checkout the Nth most recent parent. | ||
# Eg. HEAD~2 | ||
[Parameter(ValueFromPipelineByPropertyName)] | ||
[int] | ||
$RevisionNumber, | ||
|
||
# The pattern number to checkout. | ||
# This is only used when the -ResetPath parameter is provided. | ||
# If provided, this will checkout the Nth most recent parent. | ||
# Eg. HEAD^2 | ||
[Parameter(ValueFromPipelineByPropertyName)] | ||
[int] | ||
$ParentNumber, | ||
|
||
# If set, will checkout a branch in a detached state. | ||
[Parameter(ValueFromPipelineByPropertyName)] | ||
[switch] | ||
$Detach | ||
) | ||
|
||
if ($Detach) { | ||
"--detach" | ||
} | ||
|
||
if ($PullRequest) { | ||
$remoteName = git remote | Select-Object -ExpandProperty RemoteName | Select-Object -First 1 | ||
if (-not $BranchName) { | ||
$BranchName = "PR-$PullRequest" | ||
} | ||
$fetchedBranch = git fetch $remoteName "pull/$PullRequest/head:$BranchName" | ||
if (-not $fetchedBranch) { | ||
return $BranchName | ||
} | ||
$BranchName | ||
} | ||
elseif ($NewBranchName) { | ||
"-b" | ||
$NewBranchName | ||
} | ||
elseif ($ResetBranchName) { | ||
if ($PSCmdlet -and $PSCmdlet.ShouldProcess("Reset branch $ResetBranchName")) { | ||
"-B" # Beware of capital B in git | ||
$ResetBranchName | ||
} | ||
} | ||
elseif ($BranchName) { | ||
$BranchName | ||
} | ||
|
||
if ($ResetPath) { | ||
if ($ParentNumber) { | ||
"$FromBranch^$ParentNumber" | ||
} elseif ($RevisionNumber) { | ||
"$FromBranch~$RevisionNumber" | ||
} else { | ||
"$FromBranch" | ||
} | ||
|
||
foreach ($pathToReset in $ResetPath) { | ||
$pathToReset | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<# | ||
.SYNOPSIS | ||
git config list extension | ||
.DESCRIPTION | ||
Parses the output of git config --list int a PowerShell object. | ||
.EXAMPLE | ||
git config --list | ||
.EXAMPLE | ||
git config --global --list | ||
.EXAMPLE | ||
git config --list --local | ||
.EXAMPLE | ||
git config --list --show-origin | ||
#> | ||
[Management.Automation.Cmdlet("Out","Git")] # It extends Out-Git | ||
[ValidatePattern('^[\S]{0,}git config[\s\S]{1,}--list')] | ||
param() | ||
|
||
begin { | ||
$configLines = @() | ||
} | ||
|
||
process { | ||
$configLines += "$gitOut" | ||
} | ||
|
||
end { | ||
$configEntries = [Ordered]@{} | ||
|
||
# Only lines containing an = are considered configuration entries | ||
foreach ($configLine in $configLines -match '=') { | ||
# Split the line into key and value | ||
$key, $value = $configLine -split '=', 2 | ||
# If the key starts with file:, replace spaces with ? and convert to URI | ||
if ($key -match '^file:') { | ||
$key = $key -replace '\s', '?' -as [uri] | ||
} | ||
# If there are no entries, set the value | ||
if (-not $configEntries[$key]) { | ||
$configEntries[$key] = $value | ||
} else { | ||
# If there are multiple entries, convert to array | ||
$configEntries[$key] = @($configEntries[$key]) + $value | ||
} | ||
} | ||
|
||
# If there were any entries, | ||
if ($configEntries.Count) { | ||
# create a custom object | ||
$configObject = [PSCustomObject]$configEntries | ||
# decorate it as a 'git.config.list' object | ||
$configObject.PSTypeNames.insert(0,'git.config.list') | ||
# and output it. | ||
$configObject | ||
} else { | ||
# If there were no entries, output the original lines | ||
$configLines | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<# | ||
.SYNOPSIS | ||
git json format | ||
.DESCRIPTION | ||
Parses the output of git format, if the results are a series of json objects | ||
.EXAMPLE | ||
git branch --format "{'ref':'%(refname:short)','parent':'%(parent)'}" | ||
#> | ||
[Management.Automation.Cmdlet("Out","Git")] # It's an extension for Out-Git | ||
[ValidatePattern("\s-{2}format.+?[\[\{].+?[\]\}]", Options = 'IgnoreCase,IgnorePatternWhitespace' | ||
)] | ||
param() | ||
|
||
|
||
process { | ||
$gitOutJson = try { | ||
if ($gitOut) { $gitOut | ConvertFrom-Json} | ||
} catch { | ||
$null | ||
} | ||
if ($gitOutJson) { | ||
$gitOutJson | ||
return | ||
} | ||
else { | ||
return $gitOut | ||
} | ||
} |
Oops, something went wrong.