From 318aa53f27585c3b720a3a3f29ca7a054f0e6b44 Mon Sep 17 00:00:00 2001 From: Andre Riesco Date: Fri, 15 Mar 2024 15:54:11 -0300 Subject: [PATCH] projectUpdater: Fix update when file on source or dest doesn't exist Fix the update giving error when one file from the source or from the destination doesn't exist. The output now shows a merge window with the one that doesn't exist empty, like in a git diff when one of the files doesn't exist Signed-off-by: Andre Riesco --- scripts/projectUpdater.ps1 | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/scripts/projectUpdater.ps1 b/scripts/projectUpdater.ps1 index f19c85612..60e676ff2 100644 --- a/scripts/projectUpdater.ps1 +++ b/scripts/projectUpdater.ps1 @@ -18,6 +18,7 @@ function _checkArg ($_arg) { } function _checkIfFileContentIsEqual ($_file1, $_file2) { + $file1 = Get-FileHash $_file1 $file2 = Get-FileHash $_file2 @@ -28,16 +29,35 @@ function _checkIfFileContentIsEqual ($_file1, $_file2) { } } -function _openMergeWindow ($_path1, $_path2) { +function _openMergeWindow ($_updatedFile, $_currentFile) { if ($acceptAll -eq $true) { - cp $_path1 $_path2 + # If the source doesn't exist anymore on the .apollox repo of the + # template, remove it from the project being updated + if (-not (Test-Path -Path $_updatedFile )) { + Remove-Item -Path $_currentFile + } else { + Copy-Item $_updatedFile $_currentFile + } return } + # If one of the files doesn't exist create an empty one + if (-not (Test-Path -Path $_updatedFile )) { + New-Item -Path $_updatedFile -ItemType File + } elseif (-not (Test-Path -Path $_currentFile )) { + New-Item -Path $_currentFile -ItemType File + } + if ( - -not (_checkIfFileContentIsEqual $_path1 $_path2) + -not (_checkIfFileContentIsEqual $_updatedFile $_currentFile) ) { - code --wait --diff $_path1 $_path2 + code --wait --diff $_updatedFile $_currentFile + # If after the code diff the file is still empty, that means that + # this file should not be added to the project, so let's remove this + # empty file that we have just created above + if ($null -eq (Get-Content $_currentFile)) { + Remove-Item -Path $_currentFile + } } }