@@ -39,6 +39,9 @@ Write-Host "Updating google-ads-api-developer-assistant..."
3939$SettingsFile = Join-Path $ProjectDirAbs " .gemini\settings.json"
4040$TempSettingsFile = [System.IO.Path ]::GetTempFileName()
4141
42+ $CustomerIdFile = Join-Path $ProjectDirAbs " customer_id.txt"
43+ $TempCustomerIdFile = [System.IO.Path ]::GetTempFileName()
44+
4245try {
4346 # 1. Backup existing settings if they exist
4447 if (Test-Path - LiteralPath $SettingsFile ) {
5457 }
5558 }
5659
60+ # 1b. Backup customer_id.txt if it exists
61+ if (Test-Path - LiteralPath $CustomerIdFile ) {
62+ Write-Host " Backing up $CustomerIdFile ..."
63+ Copy-Item - LiteralPath $CustomerIdFile - Destination $TempCustomerIdFile - Force
64+
65+ # Reset local changes
66+ $GitStatus = git ls- files -- error- unmatch $CustomerIdFile 2> $null
67+ if ($LASTEXITCODE -eq 0 ) {
68+ Write-Host " Resetting $CustomerIdFile to avoid merge conflicts..."
69+ git checkout $CustomerIdFile
70+ }
71+ }
72+
5773 # 3. Update Repo
5874 git pull
5975 if ($LASTEXITCODE -ne 0 ) {
@@ -106,6 +122,15 @@ try {
106122 # Save merged
107123 $RepoContent | ConvertTo-Json - Depth 10 | Set-Content - LiteralPath $SettingsFile - Encoding UTF8
108124 Write-Host " Settings restored and merged successfully."
125+ Write-Host " Settings restored and merged successfully."
126+ }
127+
128+ # 4b. Restore customer_id.txt
129+ if ((Test-Path - LiteralPath $TempCustomerIdFile ) -and (Get-Item $TempCustomerIdFile ).Length -gt 0 ) {
130+ Write-Host " Restoring preserved $CustomerIdFile ..."
131+ # Always overwrite with user's backup
132+ Move-Item - LiteralPath $TempCustomerIdFile - Destination $CustomerIdFile - Force
133+ Write-Host " Restored $CustomerIdFile successfully."
109134 }
110135
111136}
@@ -118,12 +143,21 @@ catch {
118143 Copy-Item - LiteralPath $TempSettingsFile - Destination $SettingsFile - Force
119144 }
120145 }
146+ if ((Test-Path - LiteralPath $TempCustomerIdFile ) -and (Get-Item $TempCustomerIdFile ).Length -gt 0 ) {
147+ if (-not (Test-Path - LiteralPath $CustomerIdFile ) -or (Get-Item $CustomerIdFile ).Length -eq 0 ) {
148+ Write-Host " Restoring original customer_id.txt after failure..."
149+ Copy-Item - LiteralPath $TempCustomerIdFile - Destination $CustomerIdFile - Force
150+ }
151+ }
121152 exit 1
122153}
123154finally {
124155 if (Test-Path - LiteralPath $TempSettingsFile ) {
125156 Remove-Item - LiteralPath $TempSettingsFile - Force - ErrorAction SilentlyContinue
126157 }
158+ if (Test-Path - LiteralPath $TempCustomerIdFile ) {
159+ Remove-Item - LiteralPath $TempCustomerIdFile - Force - ErrorAction SilentlyContinue
160+ }
127161}
128162
129163
0 commit comments