Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement Get-Branches and split functions into seperate files
- Loading branch information
Showing
4 changed files
with
89 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,4 @@ | ||
$framework = '4.0' | ||
Set-StrictMode -Version Latest | ||
|
||
<# | ||
.Synopsis | ||
Create a new git repository | ||
.Description | ||
Initializes a new git repository at the specified path. Equivalent to "git init" | ||
.Parameter Path | ||
The path to initialize the repository in | ||
.Parameter Bare | ||
If true, creates a bare repository. Equivalent to the --bare argument to git. | ||
.Example | ||
# Create a new repository in the current directory | ||
New-Repository . | ||
#> | ||
function New-Repository($path, [switch] $bare = $false) { | ||
$resolvedPath = Resolve-Path $path | ||
[LibGit2Sharp.Repository]::Init($resolvedPath, $bare) | ||
} | ||
. .\Repository.ps1 |
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,66 @@ | ||
$framework = '4.0' | ||
Set-StrictMode -Version Latest | ||
|
||
. .\Util.ps1 | ||
|
||
<# | ||
.Synopsis | ||
Create a new git repository | ||
.Description | ||
Initializes a new git repository at the specified path. Equivalent to "git init" | ||
.Parameter Path | ||
The path to initialize the repository in | ||
.Parameter Bare | ||
If true, creates a bare repository. Equivalent to the --bare argument to git. | ||
.Example | ||
# Create a new repository in the current directory | ||
> New-Repository . | ||
#> | ||
function New-Repository($path, [switch] $bare = $false) { | ||
$resolvedPath = Resolve-Path $path | ||
[LibGit2Sharp.Repository]::Init($resolvedPath, $bare) | ||
} | ||
|
||
<# | ||
.Synopsis | ||
Creates a new repository object | ||
.Description | ||
Creates a new git repository object, which you can manipulate | ||
.Parameter Path | ||
The path to the repository | ||
.Example | ||
# Get the repository | ||
> $repository = Get-Repository path/to/my/project | ||
#> | ||
function Get-Repository($path) { | ||
$gitPath = Find-GitPath $path | ||
New-Object LibGit2Sharp.Repository($gitPath) | ||
} | ||
|
||
<# | ||
.Synopsis | ||
Gets the branches in the current repository | ||
.Example | ||
# Get the branches | ||
> Get-Branches | ||
#> | ||
function Get-Branches { | ||
$gitPath = Find-GitPath . | ||
write-host $gitPath | ||
$repository = Get-Repository $gitPath | ||
$repository.Branches | ||
} | ||
|
||
|
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,20 @@ | ||
$framework = '4.0' | ||
Set-StrictMode -Version Latest | ||
|
||
function Find-DominatingFile($path, $target) { | ||
$currentPath = Resolve-Path $path | ||
while (![string]::IsNullOrEmpty($currentPath)) { | ||
$combinedPath = [io.Path]::Combine($currentPath, $target) | ||
if (Test-Path $combinedPath) { | ||
return $combinedPath | ||
} | ||
|
||
$currentPath = [io.Path]::GetDirectoryName($currentPath) | ||
} | ||
|
||
return $null | ||
} | ||
|
||
function Find-GitPath($startingPath = '.') { | ||
Find-DominatingFile $startingPath '.git' | ||
} |