@@ -56,9 +56,6 @@ func (s *sparseCheckoutDownloader) Download() error {
5656 ctx , cancel := context .WithTimeout (context .Background (), 2 * time .Minute )
5757 defer cancel ()
5858
59- if ! s .opts .Quiet {
60- fmt .Println ("Setting up Git repository..." )
61- }
6259 if err := s .initRepo (ctx , tempDir , repoURL ); err != nil {
6360 return err
6461 }
@@ -97,7 +94,6 @@ func (s *sparseCheckoutDownloader) Download() error {
9794func (s * sparseCheckoutDownloader ) getAuthenticatedRepoURL () string {
9895 repoURL := s .opts .RepoURL
9996
100- // If URL starts with "github.com/", prefix it with "https://"
10197 if strings .HasPrefix (repoURL , "github.com/" ) {
10298 repoURL = "https://" + repoURL
10399 }
@@ -129,56 +125,32 @@ func (s *sparseCheckoutDownloader) initRepo(ctx context.Context, dir, repoURL st
129125}
130126
131127func (s * sparseCheckoutDownloader ) setupSparseCheckout (ctx context.Context , dir string ) error {
132- if _ , err := gitutil .RunGitCommand (ctx , dir , "config " , "core.sparseCheckout " , "true " ); err != nil {
128+ if _ , err := gitutil .RunGitCommand (ctx , dir , "sparse-checkout " , "init " , "--cone " ); err != nil {
133129 return errors .ParseGitError (err , "failed to enable sparse checkout" )
134130 }
135131
136- err := s .setupModernSparseCheckout (ctx , dir )
137- if err != nil {
138- return s .setupLegacySparseCheckout (ctx , dir )
139- }
140-
141- return nil
142- }
143-
144- func (s * sparseCheckoutDownloader ) setupModernSparseCheckout (ctx context.Context , dir string ) error {
145- _ , err := gitutil .RunGitCommand (ctx , dir , "sparse-checkout" , "set" , s .opts .Subdir )
146- if err != nil {
147- return err
148- }
149- return nil
150- }
151-
152- func (s * sparseCheckoutDownloader ) setupLegacySparseCheckout (_ context.Context , dir string ) error {
153- sparseCheckoutPath := filepath .Join (dir , ".git" , "info" , "sparse-checkout" )
154- sparseCheckoutDir := filepath .Dir (sparseCheckoutPath )
155-
156- if err := os .MkdirAll (sparseCheckoutDir , 0755 ); err != nil {
157- return fmt .Errorf ("failed to create sparse checkout directory: %w" , err )
158- }
159-
160- sparseCheckoutPattern := fmt .Sprintf ("%s/**" , s .opts .Subdir )
161- if err := os .WriteFile (sparseCheckoutPath , []byte (sparseCheckoutPattern ), 0644 ); err != nil {
162- return fmt .Errorf ("failed to write sparse checkout file: %w" , err )
132+ if _ , err := gitutil .RunGitCommand (ctx , dir , "sparse-checkout" , "set" , s .opts .Subdir ); err != nil {
133+ return errors .ParseGitError (err , "failed to set sparse checkout pattern" )
163134 }
164135
165136 return nil
166137}
167138
168139func (s * sparseCheckoutDownloader ) pullContent (ctx context.Context , dir string ) error {
169- args := []string {"pull" , "--depth=1" , "origin" }
140+ if ! s .opts .Quiet {
141+ fmt .Println ("Downloading content from repository..." )
142+ }
170143
144+ fetchArgs := []string {"fetch" , "--depth=1" , "--no-tags" , "origin" }
171145 if s .opts .Branch != "" {
172- args = append (args , s .opts .Branch )
146+ fetchArgs = append (fetchArgs , s .opts .Branch )
173147 }
174-
175- if ! s .opts .Quiet {
176- fmt .Println ("Downloading content from repository..." )
148+ if _ , err := gitutil .RunGitCommand (ctx , dir , fetchArgs ... ); err != nil {
149+ return errors .ParseGitError (err , "failed to fetch content" )
177150 }
178151
179- _ , err := gitutil .RunGitCommand (ctx , dir , args ... )
180- if err != nil {
181- return errors .ParseGitError (err , "failed to pull content" )
152+ if _ , err := gitutil .RunGitCommand (ctx , dir , "checkout" , "FETCH_HEAD" ); err != nil {
153+ return errors .ParseGitError (err , "failed to checkout content" )
182154 }
183155
184156 return nil
0 commit comments