@@ -42,6 +42,7 @@ import (
42
42
apu "github.com/codefresh-io/cli-v2/pkg/util/aputil"
43
43
ingressutil "github.com/codefresh-io/cli-v2/pkg/util/ingress"
44
44
wfutil "github.com/codefresh-io/cli-v2/pkg/util/workflow"
45
+ billyUtils "github.com/go-git/go-billy/v5/util"
45
46
"github.com/juju/ansiterm"
46
47
"github.com/spf13/cobra"
47
48
corev1 "k8s.io/api/core/v1"
@@ -210,7 +211,11 @@ func RunGitSourceCreate(ctx context.Context, opts *GitSourceCreateOptions) error
210
211
211
212
if opts .CreateDemoResources {
212
213
if err := createDemoResources (ctx , opts , gsRepo , gsFs ); err != nil {
213
- return fmt .Errorf ("failed to create git source demo resources: %w" , err )
214
+ return fmt .Errorf ("failed to create git-source demo resources: %w" , err )
215
+ }
216
+ } else {
217
+ if err := createPlaceholderIfNeeded (ctx , opts , gsRepo , gsFs ); err != nil {
218
+ return fmt .Errorf ("failed to create a git-source placeholder: %w" , err )
214
219
}
215
220
}
216
221
@@ -223,6 +228,7 @@ func RunGitSourceCreate(ctx context.Context, opts *GitSourceCreateOptions) error
223
228
if err := appDef .CreateApp (ctx , nil , opts .InsCloneOpts , opts .RuntimeName , store .Get ().CFGitSourceType , opts .Include , "" ); err != nil {
224
229
return fmt .Errorf ("failed to create git-source application. Err: %w" , err )
225
230
}
231
+
226
232
log .G (ctx ).Infof ("Successfully created git-source: '%s'" , opts .GsName )
227
233
228
234
return nil
@@ -258,6 +264,7 @@ func createDemoResources(ctx context.Context, opts *GitSourceCreateOptions, gsRe
258
264
commitMsg := fmt .Sprintf ("Created demo pipelines in %s Directory" , opts .GsCloneOpts .Path ())
259
265
260
266
log .G (ctx ).Info ("Pushing demo pipelines to the new git-source repo" )
267
+
261
268
if err := apu .PushWithMessage (ctx , gsRepo , commitMsg ); err != nil {
262
269
return fmt .Errorf ("failed to push demo pipelines to git-source repo: %w" , err )
263
270
}
@@ -266,6 +273,28 @@ func createDemoResources(ctx context.Context, opts *GitSourceCreateOptions, gsRe
266
273
return nil
267
274
}
268
275
276
+ func createPlaceholderIfNeeded (ctx context.Context , opts * GitSourceCreateOptions , gsRepo git.Repository , gsFs fs.FS ) error {
277
+ fi , err := gsFs .ReadDir ("." )
278
+ if err != nil {
279
+ return fmt .Errorf ("failed to read files in git-source repo. Err: %w" , err )
280
+ }
281
+
282
+ if len (fi ) == 0 {
283
+ if err = billyUtils .WriteFile (gsFs , "DUMMY" , []byte {}, 0666 ); err != nil {
284
+ return fmt .Errorf ("failed to write the git-source placeholder file. Err: %w" , err )
285
+ }
286
+
287
+ commitMsg := fmt .Sprintf ("Created a placeholder file in %s Directory" , opts .GsCloneOpts .Path ())
288
+
289
+ log .G (ctx ).Info ("Pushing placeholder file to the default-git-source repo" )
290
+ if err := apu .PushWithMessage (ctx , gsRepo , commitMsg ); err != nil {
291
+ return fmt .Errorf ("failed to push placeholder file to git-source repo: %w" , err )
292
+ }
293
+ }
294
+
295
+ return nil
296
+ }
297
+
269
298
func createCronExamplePipeline (opts * gitSourceCronExampleOptions ) error {
270
299
err := createDemoWorkflowTemplate (opts .gsFs )
271
300
if err != nil {
0 commit comments