diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2023-04-19 21:40:42 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-19 21:40:42 +0800 |
commit | e422342eebc18034ef586ec58f1e2fff0340091d (patch) | |
tree | 307264b46c1683915429083d54e9634ee4f2fc4d /modules/git | |
parent | 01214c8ada993bf5f54a4149979d140443d69410 (diff) | |
download | gitea-e422342eebc18034ef586ec58f1e2fff0340091d.tar.gz gitea-e422342eebc18034ef586ec58f1e2fff0340091d.zip |
Allow adding new files to an empty repo (#24164)

Diffstat (limited to 'modules/git')
-rw-r--r-- | modules/git/command.go | 16 | ||||
-rw-r--r-- | modules/git/repo.go | 2 | ||||
-rw-r--r-- | modules/git/repo_base_nogogit.go | 2 |
3 files changed, 14 insertions, 6 deletions
diff --git a/modules/git/command.go b/modules/git/command.go index a42d859f55..ac013d4ea1 100644 --- a/modules/git/command.go +++ b/modules/git/command.go @@ -211,10 +211,18 @@ type RunOpts struct { Env []string Timeout time.Duration UseContextTimeout bool - Dir string - Stdout, Stderr io.Writer - Stdin io.Reader - PipelineFunc func(context.Context, context.CancelFunc) error + + // Dir is the working dir for the git command, however: + // FIXME: this could be incorrect in many cases, for example: + // * /some/path/.git + // * /some/path/.git/gitea-data/data/repositories/user/repo.git + // If "user/repo.git" is invalid/broken, then running git command in it will use "/some/path/.git", and produce unexpected results + // The correct approach is to use `--git-dir" global argument + Dir string + + Stdout, Stderr io.Writer + Stdin io.Reader + PipelineFunc func(context.Context, context.CancelFunc) error } func commonBaseEnvs() []string { diff --git a/modules/git/repo.go b/modules/git/repo.go index d29ec40ae2..3637aa47c4 100644 --- a/modules/git/repo.go +++ b/modules/git/repo.go @@ -80,7 +80,7 @@ func InitRepository(ctx context.Context, repoPath string, bare bool) error { // IsEmpty Check if repository is empty. func (repo *Repository) IsEmpty() (bool, error) { var errbuf, output strings.Builder - if err := NewCommand(repo.Ctx, "show-ref", "--head", "^HEAD$"). + if err := NewCommand(repo.Ctx).AddOptionFormat("--git-dir=%s", repo.Path).AddArguments("show-ref", "--head", "^HEAD$"). Run(&RunOpts{ Dir: repo.Path, Stdout: &output, diff --git a/modules/git/repo_base_nogogit.go b/modules/git/repo_base_nogogit.go index a0216d14a6..e0f2d563b3 100644 --- a/modules/git/repo_base_nogogit.go +++ b/modules/git/repo_base_nogogit.go @@ -61,7 +61,7 @@ func OpenRepository(ctx context.Context, repoPath string) (*Repository, error) { } repo.batchWriter, repo.batchReader, repo.batchCancel = CatFileBatch(ctx, repoPath) - repo.checkWriter, repo.checkReader, repo.checkCancel = CatFileBatchCheck(ctx, repo.Path) + repo.checkWriter, repo.checkReader, repo.checkCancel = CatFileBatchCheck(ctx, repoPath) return repo, nil } |