Skip to content

Commit 62531f0

Browse files
Thomas Michaelschnatterer
authored andcommitted
Content: Print logs for RESET/UPGRADE only for existing repos
1 parent 5e3b970 commit 62531f0

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

src/main/groovy/com/cloudogu/gitops/features/Content.groovy

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,11 @@ class Content extends Feature {
150150
repoTmpDir.deleteDir()
151151
break
152152
case ContentRepoType.COPY:
153-
def repoCoordinate = createRepoCoordinatesForTypeCopy(repoConfig, contentRepoDir, mergedReposFolder, repoTmpDir, repoCoordinates)
153+
createRepoCoordinatesForTypeCopy(repoConfig, contentRepoDir, mergedReposFolder, repoTmpDir, repoCoordinates)
154154
repoTmpDir.deleteDir()
155155
break
156156
case ContentRepoType.MIRROR:
157-
def repoCoordinate = createRepoCoordinateForTypeMirror(repoConfig, repoTmpDir, repoCoordinates)
157+
createRepoCoordinateForTypeMirror(repoConfig, repoTmpDir, repoCoordinates)
158158
// intentionally not deleting repoTmpDir, it is contained in RepoCoordinates for MIRROR usage
159159
break
160160
}
@@ -304,7 +304,8 @@ class Content extends Feature {
304304
repoCoordinates.each { repoCoordinate ->
305305

306306
ScmmRepo targetRepo = repoProvider.getRepo(repoCoordinate.fullRepoName)
307-
if (isValidForPush(targetRepo, repoCoordinate)) {
307+
def isNewRepo = targetRepo.create('', scmmApiClient, false)
308+
if (isValidForPush(isNewRepo, repoCoordinate)) {
308309
targetRepo.cloneRepo()
309310

310311
switch (repoCoordinate.repoConfig.type) {
@@ -314,7 +315,7 @@ class Content extends Feature {
314315
// COPY and FOLDER_BASED same treatment
315316
case ContentRepoType.FOLDER_BASED:
316317
case ContentRepoType.COPY:
317-
handleRepoCopyingOrFolderBased(repoCoordinate, targetRepo)
318+
handleRepoCopyingOrFolderBased(repoCoordinate, targetRepo, isNewRepo)
318319
break
319320
}
320321

@@ -332,8 +333,10 @@ class Content extends Feature {
332333
* Copies repoCoordinate to targetRepo, commits and pushes
333334
* Same logic for both FOLDER_BASED and COPY repo types.
334335
*/
335-
private static void handleRepoCopyingOrFolderBased(RepoCoordinate repoCoordinate, ScmmRepo targetRepo) {
336-
clearTargetRepoIfApplicable(repoCoordinate, targetRepo)
336+
private static void handleRepoCopyingOrFolderBased(RepoCoordinate repoCoordinate, ScmmRepo targetRepo, boolean isNewRepo) {
337+
if (!isNewRepo) {
338+
clearTargetRepoIfApplicable(repoCoordinate, targetRepo)
339+
}
337340
// Avoid overwriting .git in target to avoid, because we don't need it for copying and
338341
// git pack files are typically read-only, leading to IllegalArgumentException:
339342
// File parameter 'destFile is not writable: .git/objects/pack/pack-123.pack
@@ -368,7 +371,7 @@ class Content extends Feature {
368371
"Deleting existing files in repo and replacing them with new content.")
369372
targetRepo.clearRepo()
370373
} else {
371-
log.info("OverwriteMode ${OverwriteMode.UPGRADE} set for repo '${repoCoordinate.fullRepoName}': " +
374+
log.debug("OverwriteMode ${OverwriteMode.UPGRADE} set for repo '${repoCoordinate.fullRepoName}': " +
372375
"Merging new content into existing repo. ")
373376
}
374377
}
@@ -539,9 +542,9 @@ class Content extends Feature {
539542
/**
540543
* Checks whether the repo already exists and overwrite Mode matches.
541544
*/
542-
boolean isValidForPush(ScmmRepo repo, RepoCoordinate repoCoordinate) {
543-
def isRepoCreated = repo.create('', scmmApiClient, false)
544-
if (!isRepoCreated && OverwriteMode.INIT == repoCoordinate.repoConfig.overwriteMode) {
545+
static boolean isValidForPush(boolean isNewRepo, RepoCoordinate repoCoordinate) {
546+
547+
if (!isNewRepo && OverwriteMode.INIT == repoCoordinate.repoConfig.overwriteMode) {
545548
log.warn("OverwriteMode ${OverwriteMode.INIT} set for repo '${repoCoordinate.fullRepoName}' " +
546549
"and repo already exists in target: Not pushing content!" +
547550
"If you want to override, set ${OverwriteMode.UPGRADE} or ${OverwriteMode.RESET} .")

0 commit comments

Comments
 (0)