@@ -42,6 +42,7 @@ import (
4242 apu "github.com/codefresh-io/cli-v2/pkg/util/aputil"
4343 ingressutil "github.com/codefresh-io/cli-v2/pkg/util/ingress"
4444 wfutil "github.com/codefresh-io/cli-v2/pkg/util/workflow"
45+ billyUtils "github.com/go-git/go-billy/v5/util"
4546 "github.com/juju/ansiterm"
4647 "github.com/spf13/cobra"
4748 corev1 "k8s.io/api/core/v1"
@@ -210,7 +211,11 @@ func RunGitSourceCreate(ctx context.Context, opts *GitSourceCreateOptions) error
210211
211212 if opts .CreateDemoResources {
212213 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 )
214219 }
215220 }
216221
@@ -223,6 +228,7 @@ func RunGitSourceCreate(ctx context.Context, opts *GitSourceCreateOptions) error
223228 if err := appDef .CreateApp (ctx , nil , opts .InsCloneOpts , opts .RuntimeName , store .Get ().CFGitSourceType , opts .Include , "" ); err != nil {
224229 return fmt .Errorf ("failed to create git-source application. Err: %w" , err )
225230 }
231+
226232 log .G (ctx ).Infof ("Successfully created git-source: '%s'" , opts .GsName )
227233
228234 return nil
@@ -258,6 +264,7 @@ func createDemoResources(ctx context.Context, opts *GitSourceCreateOptions, gsRe
258264 commitMsg := fmt .Sprintf ("Created demo pipelines in %s Directory" , opts .GsCloneOpts .Path ())
259265
260266 log .G (ctx ).Info ("Pushing demo pipelines to the new git-source repo" )
267+
261268 if err := apu .PushWithMessage (ctx , gsRepo , commitMsg ); err != nil {
262269 return fmt .Errorf ("failed to push demo pipelines to git-source repo: %w" , err )
263270 }
@@ -266,6 +273,28 @@ func createDemoResources(ctx context.Context, opts *GitSourceCreateOptions, gsRe
266273 return nil
267274}
268275
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+
269298func createCronExamplePipeline (opts * gitSourceCronExampleOptions ) error {
270299 err := createDemoWorkflowTemplate (opts .gsFs )
271300 if err != nil {
0 commit comments