@@ -248,7 +248,7 @@ func (r *gitRepo) loadRefs(ctx context.Context) (map[string]string, error) {
248248 r .refsErr = err
249249 return
250250 }
251- out , gitErr := r .runGit (ctx , "git" , "ls-remote" , "-q" , r .remote )
251+ out , gitErr := r .runGit (ctx , "git" , "ls-remote" , "-q" , "--end-of-options" , r .remote )
252252 release ()
253253
254254 if gitErr != nil {
@@ -534,7 +534,7 @@ func (r *gitRepo) stat(ctx context.Context, rev string) (info *RevInfo, err erro
534534 if fromTag && ! slices .Contains (info .Tags , tag ) {
535535 // The local repo includes the commit hash we want, but it is missing
536536 // the corresponding tag. Add that tag and try again.
537- _ , err := r .runGit (ctx , "git" , "tag" , tag , hash )
537+ _ , err := r .runGit (ctx , "git" , "tag" , "--end-of-options" , tag , hash )
538538 if err != nil {
539539 return nil , err
540540 }
@@ -583,7 +583,7 @@ func (r *gitRepo) stat(ctx context.Context, rev string) (info *RevInfo, err erro
583583 // an apparent Git bug introduced in Git 2.21 (commit 61c771),
584584 // which causes the handler for protocol version 1 to sometimes miss
585585 // tags that point to the requested commit (see https://go.dev/issue/56881).
586- _ , err = r .runGit (ctx , "git" , "-c" , "protocol.version=2" , "fetch" , "-f" , "--depth=1" , r .remote , refspec )
586+ _ , err = r .runGit (ctx , "git" , "-c" , "protocol.version=2" , "fetch" , "-f" , "--depth=1" , "--end-of-options" , r .remote , refspec )
587587 release ()
588588
589589 if err == nil {
@@ -629,12 +629,12 @@ func (r *gitRepo) fetchRefsLocked(ctx context.Context) error {
629629 }
630630 defer release ()
631631
632- if _ , err := r .runGit (ctx , "git" , "fetch" , "-f" , r .remote , "refs/heads/*:refs/heads/*" , "refs/tags/*:refs/tags/*" ); err != nil {
632+ if _ , err := r .runGit (ctx , "git" , "fetch" , "-f" , "--end-of-options" , r .remote , "refs/heads/*:refs/heads/*" , "refs/tags/*:refs/tags/*" ); err != nil {
633633 return err
634634 }
635635
636636 if _ , err := os .Stat (filepath .Join (r .dir , "shallow" )); err == nil {
637- if _ , err := r .runGit (ctx , "git" , "fetch" , "--unshallow" , "-f" , r .remote ); err != nil {
637+ if _ , err := r .runGit (ctx , "git" , "fetch" , "--unshallow" , "-f" , "--end-of-options" , r .remote ); err != nil {
638638 return err
639639 }
640640 }
@@ -647,7 +647,7 @@ func (r *gitRepo) fetchRefsLocked(ctx context.Context) error {
647647// statLocal returns a new RevInfo describing rev in the local git repository.
648648// It uses version as info.Version.
649649func (r * gitRepo ) statLocal (ctx context.Context , version , rev string ) (* RevInfo , error ) {
650- out , err := r .runGit (ctx , "git" , "-c" , "log.showsignature=false" , "log" , "--no-decorate" , "-n1" , "--format=format:%H %ct %D" , rev , "--" )
650+ out , err := r .runGit (ctx , "git" , "-c" , "log.showsignature=false" , "log" , "--no-decorate" , "-n1" , "--format=format:%H %ct %D" , "--end-of-options" , rev , "--" )
651651 if err != nil {
652652 // Return info with Origin.RepoSum if possible to allow caching of negative lookup.
653653 var info * RevInfo
@@ -737,7 +737,7 @@ func (r *gitRepo) ReadFile(ctx context.Context, rev, file string, maxSize int64)
737737 if err != nil {
738738 return nil , err
739739 }
740- out , err := r .runGit (ctx , "git" , "cat-file" , "blob" , info .Name + ":" + file )
740+ out , err := r .runGit (ctx , "git" , "cat-file" , "--end-of-options" , " blob" , info .Name + ":" + file )
741741 if err != nil {
742742 return nil , fs .ErrNotExist
743743 }
@@ -755,7 +755,7 @@ func (r *gitRepo) RecentTag(ctx context.Context, rev, prefix string, allowed fun
755755 // result is definitive.
756756 describe := func () (definitive bool ) {
757757 var out []byte
758- out , err = r .runGit (ctx , "git" , "for-each-ref" , "--format" , " %(refname)" , "refs/tags" , " --merged" , rev )
758+ out , err = r .runGit (ctx , "git" , "for-each-ref" , "--format= %(refname)" , "--merged=" + rev )
759759 if err != nil {
760760 return true
761761 }
@@ -904,7 +904,7 @@ func (r *gitRepo) ReadZip(ctx context.Context, rev, subdir string, maxSize int64
904904 // TODO: Use maxSize or drop it.
905905 args := []string {}
906906 if subdir != "" {
907- args = append (args , "--" , subdir )
907+ args = append (args , subdir )
908908 }
909909 info , err := r .Stat (ctx , rev ) // download rev into local git repo
910910 if err != nil {
@@ -926,7 +926,7 @@ func (r *gitRepo) ReadZip(ctx context.Context, rev, subdir string, maxSize int64
926926 // text file line endings. Setting -c core.autocrlf=input means only
927927 // translate files on the way into the repo, not on the way out (archive).
928928 // The -c core.eol=lf should be unnecessary but set it anyway.
929- archive , err := r .runGit (ctx , "git" , "-c" , "core.autocrlf=input" , "-c" , "core.eol=lf" , "archive" , "--format=zip" , "--prefix=prefix/" , info .Name , args )
929+ archive , err := r .runGit (ctx , "git" , "-c" , "core.autocrlf=input" , "-c" , "core.eol=lf" , "archive" , "--format=zip" , "--prefix=prefix/" , "--end-of-options" , info .Name , args )
930930 if err != nil {
931931 if bytes .Contains (err .(* RunError ).Stderr , []byte ("did not match any files" )) {
932932 return nil , fs .ErrNotExist
0 commit comments