mirror of
https://github.com/Baipyrus/dotfiles.git
synced 2024-11-14 23:23:50 +00:00
detecting existing repository in current directory
This commit is contained in:
parent
e2797da0b7
commit
e6e8a3212d
@ -4,13 +4,41 @@ $alacrittyConfigDir = "$env:APPDATA\alacritty"
|
|||||||
$psProfile = "$env:USERPROFILE\Documents\PowerShell\Microsoft.PowerShell_profile.ps1"
|
$psProfile = "$env:USERPROFILE\Documents\PowerShell\Microsoft.PowerShell_profile.ps1"
|
||||||
$repoUrl = "https://github.com/Baipyrus/dotfiles.git"
|
$repoUrl = "https://github.com/Baipyrus/dotfiles.git"
|
||||||
|
|
||||||
# Clone dotfiles repository to TMP if not already inside it
|
# Function to determine if the current directory is the dotfiles repository
|
||||||
if (-not (Test-Path $dotfilesRepo))
|
function IsInDotfilesRepo
|
||||||
{
|
{
|
||||||
Write-Host "Cloning dotfiles repository..." -ForegroundColor Cyan
|
param ([string]$currentDir)
|
||||||
git clone $repoUrl $dotfilesRepo
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$isRepo = git -C $currentDir rev-parse --is-inside-work-tree 2>$null
|
||||||
|
$originUrl = git -C $currentDir remote get-url origin 2>$null
|
||||||
|
return $isRepo -eq 'true' -and $originUrl -eq $repoUrl
|
||||||
|
} catch
|
||||||
|
{
|
||||||
|
return $false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Check if the script is running inside the dotfiles repository
|
||||||
|
$currentDir = (Get-Location).Path
|
||||||
|
|
||||||
|
if (IsInDotfilesRepo -currentDir $currentDir)
|
||||||
|
{
|
||||||
|
Write-Host "Already inside the dotfiles repository. Skipping clone step and pulling..." -ForegroundColor Yellow
|
||||||
|
$dotfilesRepo = $currentDir
|
||||||
|
git -C $dotfilesRepo pull
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
Write-Host "Pulling latest changes from dotfiles repository..." -ForegroundColor Cyan
|
# Clone dotfiles repository to TMP if not already inside it
|
||||||
git -C $dotfilesRepo pull
|
if (-not (Test-Path $dotfilesRepo))
|
||||||
|
{
|
||||||
|
Write-Host "Cloning dotfiles repository..." -ForegroundColor Cyan
|
||||||
|
git clone $repoUrl $dotfilesRepo
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
Write-Host "Pulling latest changes from dotfiles repository..." -ForegroundColor Cyan
|
||||||
|
git -C $dotfilesRepo pull
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user