aboutsummaryrefslogtreecommitdiffstats
path: root/modules/git
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2023-04-19 21:40:42 +0800
committerGitHub <noreply@github.com>2023-04-19 21:40:42 +0800
commite422342eebc18034ef586ec58f1e2fff0340091d (patch)
tree307264b46c1683915429083d54e9634ee4f2fc4d /modules/git
parent01214c8ada993bf5f54a4149979d140443d69410 (diff)
downloadgitea-e422342eebc18034ef586ec58f1e2fff0340091d.tar.gz
gitea-e422342eebc18034ef586ec58f1e2fff0340091d.zip
Allow adding new files to an empty repo (#24164)
![image](https://user-images.githubusercontent.com/2114189/232561612-2bfcfd0a-fc04-47ba-965f-5d0bcea46c54.png)
Diffstat (limited to 'modules/git')
-rw-r--r--modules/git/command.go16
-rw-r--r--modules/git/repo.go2
-rw-r--r--modules/git/repo_base_nogogit.go2
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
}