Skip to content

Commit

Permalink
implement Get-Branches and split functions into seperate files
Browse files Browse the repository at this point in the history
  • Loading branch information
cbilson committed May 8, 2011
1 parent 704b1ec commit d1a4546
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 23 deletions.
2 changes: 2 additions & 0 deletions Git-Got.nuspec
Expand Up @@ -15,6 +15,8 @@
<file src="readme.md" />
<file src="src\Git-Got.psm1" />
<file src="src\Git-Got.psd1" />
<file src="src\Util.ps1" />
<file src="src\Repository.ps1" />
<file src="src\git2.dll" />
<file src="src\LibGit2Sharp.dll" />
</files>
Expand Down
24 changes: 1 addition & 23 deletions src/Git-Got.psm1
@@ -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
66 changes: 66 additions & 0 deletions src/Repository.ps1
@@ -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
}


20 changes: 20 additions & 0 deletions src/Util.ps1
@@ -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'
}

0 comments on commit d1a4546

Please sign in to comment.