Skip to content

Instantly share code, notes, and snippets.

@nmbell
Created April 12, 2021 03:13
Show Gist options
  • Save nmbell/10dad7587ef640618036461c7d212981 to your computer and use it in GitHub Desktop.
Save nmbell/10dad7587ef640618036461c7d212981 to your computer and use it in GitHub Desktop.
Powdrgit Help Examples - Setup Script
# Set the location of the root folder
$rootFolder = 'C:\PowdrgitExamples'
$tempFolder = $Env:TEMP
If (!(Test-Path -Path $rootFolder))
{
# Create the root folder if necessary
New-Item -Path $rootFolder -ItemType Directory -Force -ErrorAction Stop | Out-Null
# Create a non-git folder
New-Item -Path "$rootFolder\NotAGitRepo"-ItemType Directory -Force -ErrorAction Stop | Out-Null
# Create the git repositories
Push-Location -StackName _HelpExampleSetup # store our current location
git init "$tempFolder\MyToolbox_FakeRemote" --initial-branch=main 2>&1 | Out-Null
Set-Location -Path "$tempFolder\MyToolbox_FakeRemote"
git commit -m "Initial commit" --allow-empty 2>&1 | Out-Null
git checkout -b feature1 2>&1 | Out-Null
git commit -m "feature1 commit" --allow-empty 2>&1 | Out-Null
git checkout -b release 2>&1 | Out-Null
git commit -m "release commit" --allow-empty 2>&1 | Out-Null
git checkout main 2>&1 | Out-Null
git clone "$tempFolder\MyToolbox_FakeRemote" "$rootFolder\MyToolbox" 2>&1 | Out-Null
Set-Location -Path "$rootFolder\MyToolbox"
git checkout feature1 2>&1 | Out-Null
git branch feature1 --set-upstream-to="remotes/origin/feature1" 2>&1 | Out-Null
New-Item -Path "$rootFolder\MyToolbox\feature1_File1.txt" -ItemType File | Out-Null
git add . 2>&1 | Out-Null
git commit -m "Add feature1_File1.txt" 2>&1 | Out-Null
git tag lightweightTag 2>&1 | Out-Null
git checkout release 2>&1 | Out-Null
git branch release --set-upstream-to="remotes/origin/release" 2>&1 | Out-Null
git tag -a annotatedTag -m "This is an annotated tag" 2>&1 | Out-Null
git checkout main 2>&1 | Out-Null
git branch main --set-upstream-to="remotes/origin/main" 2>&1 | Out-Null
git merge feature1 -m "Merging from feature1" --no-ff 2>&1 | Out-Null
Set-Location -Path "$tempFolder\MyToolbox_FakeRemote"
git checkout -b feature2 2>&1 | Out-Null
git checkout main 2>&1 | Out-Null
Set-Location -Path "$rootFolder\MyToolbox"
git fetch 2>&1 | Out-Null
Set-Location -Path "$rootFolder\MyToolbox"
git checkout main 2>&1 | Out-Null
git checkout -b feature3 2>&1 | Out-Null
New-Item -Path "$rootFolder\MyToolbox\feature3_FileA.txt" -ItemType File | Out-Null
git add . 2>&1 | Out-Null
git commit -m "Add feature3_FileA.txt" 2>&1 | Out-Null
git checkout main 2>&1 | Out-Null
git init "$rootFolder\Project1" 2>&1 --initial-branch=main | Out-Null
Set-Location -Path "$rootFolder\Project1"
git commit -m "Initial commit" --allow-empty 2>&1 | Out-Null
git checkout -b newfeature 2>&1 | Out-Null
Pop-Location -StackName _HelpExampleSetup # move back to our original location
}
<# # Clean up
Remove-Item -Path $rootFolder -Recurse -Force
Remove-Item -Path "$tempFolder\MyToolbox_FakeRemote" -Recurse -Force
#>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment