Skip to content

Commit 5aecffc

Browse files
committed
Merge pull request microsoft#232 from zhengbli/master
Fix microsoft#148 Avoid running tf command if it is not tf environment
2 parents 29f9c7e + b2af260 commit 5aecffc

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

Nodejs/Setup/BuildRelease.ps1

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -325,9 +325,12 @@ if ($name) {
325325
$version_file_backed_up = 0
326326
# Force use of a backup if there are pending changes to $version_file
327327
$version_file_force_backup = 0
328-
if (-not (tf status $version_file /format:detailed | Select-String "There are no pending changes.")) {
329-
Write-Output "$version_file has pending changes. Using backup instead of tf undo."
330-
$version_file_force_backup = 1
328+
$has_tf_workspace = (-not (tf workspaces | Select-String -pattern "No workspace", "Unable to determine the workspace"))
329+
if ($has_tf_workspace) {
330+
if (-not (tf status $version_file /format:detailed | Select-String "There are no pending changes.")) {
331+
Write-Output "$version_file has pending changes. Using backup instead of tf undo."
332+
$version_file_force_backup = 1
333+
}
331334
}
332335
$version_file_is_readonly = $version_file.Attributes -band [io.FileAttributes]::ReadOnly
333336

@@ -433,7 +436,7 @@ if (-not $skipclean) {
433436

434437
$logdir = mkdir "$outdir\Logs" -Force
435438

436-
if ($scorch) {
439+
if ($scorch -and $has_tf_workspace) {
437440
tfpt scorch $buildroot /noprompt
438441
}
439442

@@ -442,7 +445,7 @@ $failed_logs = @()
442445
Push-Location $buildroot
443446
try {
444447
$successful = $false
445-
if (-not $version_file_force_backup) {
448+
if ((-not $version_file_force_backup) -and $has_tf_workspace) {
446449
tf edit $version_file | Out-Null
447450
}
448451
if ($version_file_force_backup -or -not $?) {
@@ -636,7 +639,7 @@ try {
636639
Set-ItemProperty $version_file -Name IsReadOnly -Value $true
637640
}
638641
Write-Output "Restored $version_file"
639-
} elseif (-not $version_file_force_backup) {
642+
} elseif ((-not $version_file_force_backup) -and $has_tf_workspace) {
640643
tf undo /noprompt $version_file | Out-Null
641644
}
642645

0 commit comments

Comments
 (0)