mirror of
				https://github.com/go-gitea/gitea
				synced 2025-11-04 05:18:25 +00:00 
			
		
		
		
	Backport #30878 by wxiaoguang Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
		@@ -7,7 +7,6 @@ package git
 | 
			
		||||
import (
 | 
			
		||||
	"bytes"
 | 
			
		||||
	"context"
 | 
			
		||||
	"errors"
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"io"
 | 
			
		||||
	"net/url"
 | 
			
		||||
@@ -63,32 +62,6 @@ func IsRepoURLAccessible(ctx context.Context, url string) bool {
 | 
			
		||||
	return err == nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// GetObjectFormatOfRepo returns the hash type of repository at a given path
 | 
			
		||||
func GetObjectFormatOfRepo(ctx context.Context, repoPath string) (ObjectFormat, error) {
 | 
			
		||||
	var stdout, stderr strings.Builder
 | 
			
		||||
 | 
			
		||||
	err := NewCommand(ctx, "hash-object", "--stdin").Run(&RunOpts{
 | 
			
		||||
		Dir:    repoPath,
 | 
			
		||||
		Stdout: &stdout,
 | 
			
		||||
		Stderr: &stderr,
 | 
			
		||||
		Stdin:  &strings.Reader{},
 | 
			
		||||
	})
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if stderr.Len() > 0 {
 | 
			
		||||
		return nil, errors.New(stderr.String())
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	h, err := NewIDFromString(strings.TrimRight(stdout.String(), "\n"))
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return h.Type(), nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// InitRepository initializes a new Git repository.
 | 
			
		||||
func InitRepository(ctx context.Context, repoPath string, bare bool, objectFormatName string) error {
 | 
			
		||||
	err := os.MkdirAll(repoPath, os.ModePerm)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user