diff options
| -rw-r--r-- | .config/powershell/initialize.ps1 | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/.config/powershell/initialize.ps1 b/.config/powershell/initialize.ps1 index 464f245..f30bb14 100644 --- a/.config/powershell/initialize.ps1 +++ b/.config/powershell/initialize.ps1 @@ -88,13 +88,37 @@ function cloneDotfiles { } Add-Content -Path "$env:USERPROFILE\.gitignore" -Value ".cfg" + + if (Test-Path -Path $dotfiles_dir) { + config pull | Out-Null + $update = $true + } else { + git clone --bare $dotfiles_url $dotfiles_dir | Out-Null + $update = $false + } + $std_err_output = config checkout 2>&1 + if ($std_err_output -match "following untracked working tree files would be overwritten") { - Write-Warning "Some untracked files will be overwritten. Aborting." - return 5 + if (-not $update) { + config checkout | Out-Null + } } - config config --local status.showUntrackedFiles no + + if ($update -or (Read-Host "Do you want to overwrite existing files and continue with the dotfiles setup? [Y/n]" -eq "Y")) { + config fetch origin main:main | Out-Null + config reset --hard main | Out-Null + config checkout -f + if ($?) { + Write-Host "Successfully imported $dotfiles_dir." + } else { + handle_error "Mission failed." + } + } else { + handle_error "Aborted by user. Exiting..." + } + return 0 } |
