Created
May 6, 2020 11:32
-
-
Save wtrsltnk/46f60521c48b1ff5de0094f9ed37e894 to your computer and use it in GitHub Desktop.
Create new repository from template repository on disk
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
$TemplateRepoName = $args[0] | |
if ($args.count -le 1) { | |
$NewRepoName = Read-Host -Prompt 'What is the name of the new repository?' | |
} else { | |
$NewRepoName = $args[1] | |
} | |
$TemplateName = Split-Path $TemplateRepoName -leaf | |
if (Test-Path ".\$NewRepoName") { | |
Write-Host "There already exists a folder where the new repo should be created" | |
Break | |
} else { | |
Copy-Item "$TemplateRepoName" -Destination ".\$NewRepoName" -Recurse | |
if (Test-Path ".\$NewRepoName\.git"){ | |
Remove-Item -LiteralPath ".\$NewRepoName\.git\" -Force -Recurse | |
} | |
Push-Location ".\$NewRepoName" | |
Git init | |
Git add * | |
Git commit -m "Initial commit from template $TemplateName" | |
((Get-Content -path CMakeLists.txt -Raw) -replace $TemplateName,$NewRepoName) | Set-Content -Path CMakeLists.txt | |
if (Test-Path README.md){ | |
((Get-Content -path README.md -Raw) -replace $TemplateName,$NewRepoName) | Set-Content -Path README.md | |
} | |
Git add * | |
Git commit -m "Replaced the template name in with the new repo name in some files" | |
Pop-Location | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment