Skip to content

Commit

Permalink
projectUpdater: Fix update when file on source or dest doesn't exist
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
andreriesco committed Mar 15, 2024
1 parent 814b932 commit 318aa53
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions scripts/projectUpdater.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ function _checkArg ($_arg) {
}

function _checkIfFileContentIsEqual ($_file1, $_file2) {

$file1 = Get-FileHash $_file1
$file2 = Get-FileHash $_file2

Expand All @@ -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
}
}
}

Expand Down

0 comments on commit 318aa53

Please sign in to comment.