Skip to content

Commit 146f3f2

Browse files
committed
commit customized content only if user repository was new one
1 parent 3f80dcb commit 146f3f2

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

stp.ps1

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ Begin {
4848
# name of GPO that will be used for connecting computers to this solution
4949
$GPOname = 'PS_env_set_up'
5050

51+
$userRepositoryWasntEmpty = $false
52+
5153
# hardcoded PATHs for TEST installation
5254
$remoteRepository = "$env:SystemDrive\myCompanyRepository_remote"
5355
#endregion Variables
@@ -1398,6 +1400,9 @@ Your input will be stored to '$iniFile'. So next time you start this script, its
13981400
_unsetVariable userRepository
13991401
_setVariable userRepository "path to ROOT of your locally cloned repository '$repositoryURL'"
14001402
}
1403+
1404+
# make a note whether cloned repository is brand new or was already set up
1405+
$userRepositoryWasntEmpty = Test-Path "$userRepository\Custom\Repo_Sync\Repo_Sync.ps1" -ErrorAction SilentlyContinue
14011406
} else {
14021407
$userRepository = "$env:SystemDrive\myCompanyRepository"
14031408

@@ -1442,7 +1447,7 @@ Your input will be stored to '$iniFile'. So next time you start this script, its
14421447
$userDomain = "$env:COMPUTERNAME.com"
14431448
}
14441449
Write-Host "- Configuring repository '$userRepository'" -ForegroundColor Green
1445-
" - activating GIT Hooks, creating symlink for PowerShell snippets, commiting&pushing changes, etc"
1450+
" - activating GIT Hooks, creating symlink for PowerShell snippets, commiting&pushing changes (if new repository), etc"
14461451

14471452
if ($testInstallation -or (!$noEnvModification -and !(_skip))) {
14481453
$currPath = Get-Location
@@ -1475,9 +1480,16 @@ Your input will be stored to '$iniFile'. So next time you start this script, its
14751480

14761481
# commit without using hooks, to avoid possible problem with checks (because of wrong encoding, missing PSScriptAnalyzer etc), that could stop it
14771482
" - commiting & pushing changes to repository $repositoryURL"
1478-
$null = git add .
1479-
$null = _startProcess git "commit --no-verify -m initial" -outputErr2Std -dontWait
1480-
$null = _startProcess git "push --no-verify" -outputErr2Std
1483+
if ($testInstallation -or !$userRepositoryWasntEmpty) {
1484+
# user repo was empty before my customized content was copied to it or this is TEST installation
1485+
# it is safe to automatically do commit&push
1486+
$null = git add .
1487+
$null = _startProcess git "commit --no-verify -m initial" -outputErr2Std -dontWait
1488+
$null = _startProcess git "push --no-verify" -outputErr2Std
1489+
} else {
1490+
Write-Warning "Skipped.`n`nYour repository wasn't empty before customized content was copied a.k.a. some of your content could be lost. Check manually changed files (in VSC 'Source Control' tab) and commit&push just safe changes before continue!"
1491+
_pressKeyToContinue
1492+
}
14811493

14821494
" - activating GIT hooks for automation of checks, git push etc"
14831495
$null = _startProcess git 'config core.hooksPath ".\.githooks"'

0 commit comments

Comments
 (0)