Skip to content

Commit 976df17

Browse files
committed
Merge branch 'lunny/fix_git_config_conflict' of github.com:lunny/gitea into lunny/fix_git_config_conflict
2 parents 98bc0df + 70ef126 commit 976df17

File tree

11 files changed

+66
-85
lines changed

11 files changed

+66
-85
lines changed

modules/git/repo.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,21 @@ type GPGSettings struct {
3131
Format string
3232
}
3333

34-
const PrettyLogFormat = `--pretty=format:%H`
34+
const prettyLogFormat = `--pretty=format:%H`
3535

3636
// GetAllCommitsCount returns count of all commits in repository
3737
func (repo *Repository) GetAllCommitsCount() (int64, error) {
3838
return AllCommitsCount(repo.Ctx, repo.Path, false)
3939
}
4040

41-
func (repo *Repository) ParsePrettyFormatLogToList(logs []byte) ([]*Commit, error) {
41+
func (repo *Repository) ShowPrettyFormatLogToList(ctx context.Context, revisionRange string) ([]*Commit, error) {
42+
// avoid: ambiguous argument 'refs/a...refs/b': unknown revision or path not in the working tree. Use '--': 'git <command> [<revision>...] -- [<file>...]'
43+
logs, _, err := NewCommand("log").AddArguments(prettyLogFormat).
44+
AddDynamicArguments(revisionRange).AddArguments("--").
45+
RunStdBytes(ctx, &RunOpts{Dir: repo.Path})
46+
if err != nil {
47+
return nil, err
48+
}
4249
return repo.parsePrettyFormatLogToList(logs)
4350
}
4451

modules/git/repo_commit.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func (repo *Repository) getCommitByPathWithID(id ObjectID, relpath string) (*Com
5959
relpath = `\` + relpath
6060
}
6161

62-
stdout, _, runErr := NewCommand("log", "-1", PrettyLogFormat).AddDynamicArguments(id.String()).AddDashesAndList(relpath).RunStdString(repo.Ctx, &RunOpts{Dir: repo.Path})
62+
stdout, _, runErr := NewCommand("log", "-1", prettyLogFormat).AddDynamicArguments(id.String()).AddDashesAndList(relpath).RunStdString(repo.Ctx, &RunOpts{Dir: repo.Path})
6363
if runErr != nil {
6464
return nil, runErr
6565
}
@@ -74,7 +74,7 @@ func (repo *Repository) getCommitByPathWithID(id ObjectID, relpath string) (*Com
7474

7575
// GetCommitByPath returns the last commit of relative path.
7676
func (repo *Repository) GetCommitByPath(relpath string) (*Commit, error) {
77-
stdout, _, runErr := NewCommand("log", "-1", PrettyLogFormat).AddDashesAndList(relpath).RunStdBytes(repo.Ctx, &RunOpts{Dir: repo.Path})
77+
stdout, _, runErr := NewCommand("log", "-1", prettyLogFormat).AddDashesAndList(relpath).RunStdBytes(repo.Ctx, &RunOpts{Dir: repo.Path})
7878
if runErr != nil {
7979
return nil, runErr
8080
}
@@ -94,7 +94,7 @@ func (repo *Repository) commitsByRangeWithTime(id ObjectID, page, pageSize int,
9494
cmd := NewCommand("log").
9595
AddOptionFormat("--skip=%d", (page-1)*pageSize).
9696
AddOptionFormat("--max-count=%d", pageSize).
97-
AddArguments(PrettyLogFormat).
97+
AddArguments(prettyLogFormat).
9898
AddDynamicArguments(id.String())
9999

100100
if not != "" {
@@ -141,7 +141,7 @@ func (repo *Repository) searchCommits(id ObjectID, opts SearchCommitsOptions) ([
141141
}
142142

143143
// create new git log command with limit of 100 commits
144-
cmd := NewCommand("log", "-100", PrettyLogFormat).AddDynamicArguments(id.String())
144+
cmd := NewCommand("log", "-100", prettyLogFormat).AddDynamicArguments(id.String())
145145

146146
// pretend that all refs along with HEAD were listed on command line as <commis>
147147
// https://git-scm.com/docs/git-log#Documentation/git-log.txt---all
@@ -175,7 +175,7 @@ func (repo *Repository) searchCommits(id ObjectID, opts SearchCommitsOptions) ([
175175
// ignore anything not matching a valid sha pattern
176176
if id.Type().IsValid(v) {
177177
// create new git log command with 1 commit limit
178-
hashCmd := NewCommand("log", "-1", PrettyLogFormat)
178+
hashCmd := NewCommand("log", "-1", prettyLogFormat)
179179
// add previous arguments except for --grep and --all
180180
addCommonSearchArgs(hashCmd)
181181
// add keyword as <commit>
@@ -410,7 +410,7 @@ func (repo *Repository) CommitsCountBetween(start, end string) (int64, error) {
410410

411411
// commitsBefore the limit is depth, not total number of returned commits.
412412
func (repo *Repository) commitsBefore(id ObjectID, limit int) ([]*Commit, error) {
413-
cmd := NewCommand("log", PrettyLogFormat)
413+
cmd := NewCommand("log", prettyLogFormat)
414414
if limit > 0 {
415415
cmd.AddOptionFormat("-%d", limit)
416416
}
@@ -536,7 +536,7 @@ func (repo *Repository) AddLastCommitCache(cacheKey, fullName, sha string) error
536536

537537
// GetCommitBranchStart returns the commit where the branch diverged
538538
func (repo *Repository) GetCommitBranchStart(env []string, branch, endCommitID string) (string, error) {
539-
cmd := NewCommand("log", PrettyLogFormat)
539+
cmd := NewCommand("log", prettyLogFormat)
540540
cmd.AddDynamicArguments(endCommitID)
541541

542542
stdout, _, runErr := cmd.RunStdBytes(repo.Ctx, &RunOpts{

modules/gitrepo/config.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"code.gitea.io/gitea/modules/globallock"
1515
)
1616

17-
func GetGitConfig(ctx context.Context, repo Repository, key string) (string, error) {
17+
func GitConfigGet(ctx context.Context, repo Repository, key string) (string, error) {
1818
result, _, err := git.NewCommand("config", "--get").
1919
AddDynamicArguments(key).
2020
RunStdString(ctx, &git.RunOpts{Dir: repoPath(repo)})
@@ -31,8 +31,8 @@ func getRepoConfigLockKey(repoStoragePath string) string {
3131
return "repo-config:" + repoStoragePath
3232
}
3333

34-
// AddGitConfig add a git configuration key to a specific value for the given repository.
35-
func AddGitConfig(ctx context.Context, repo Repository, key, value string) error {
34+
// GitConfigAdd add a git configuration key to a specific value for the given repository.
35+
func GitConfigAdd(ctx context.Context, repo Repository, key, value string) error {
3636
releaser, err := globallock.Lock(ctx, getRepoConfigLockKey(repo.RelativePath()))
3737
if err != nil {
3838
return err
@@ -45,20 +45,20 @@ func AddGitConfig(ctx context.Context, repo Repository, key, value string) error
4545
return err
4646
}
4747

48-
// UpdateGitConfig updates a git configuration key to a specific value for the given repository.
48+
// GitConfigSet updates a git configuration key to a specific value for the given repository.
4949
// If the key does not exist, it will be created.
5050
// If the key exists, it will be updated to the new value.
51-
func UpdateGitConfig(ctx context.Context, repo Repository, key, value string) (string, error) {
51+
func GitConfigSet(ctx context.Context, repo Repository, key, value string) error {
5252
releaser, err := globallock.Lock(ctx, getRepoConfigLockKey(repo.RelativePath()))
5353
if err != nil {
54-
return "", err
54+
return err
5555
}
5656
defer releaser()
5757

58-
value, _, err1 := git.NewCommand("config").
58+
_, _, err = git.NewCommand("config").
5959
AddDynamicArguments(key, value).
6060
RunStdString(ctx, &git.RunOpts{Dir: repoPath(repo)})
61-
return value, err1
61+
return err
6262
}
6363

6464
type RemoteOption string
@@ -68,7 +68,7 @@ const (
6868
RemoteOptionMirrorFetch RemoteOption = "--mirror=fetch"
6969
)
7070

71-
func AddGitRemote(ctx context.Context, repo Repository, remoteName, remoteURL string, options ...RemoteOption) error {
71+
func GitRemoteAdd(ctx context.Context, repo Repository, remoteName, remoteURL string, options ...RemoteOption) error {
7272
releaser, err := globallock.Lock(ctx, getRepoConfigLockKey(repo.RelativePath()))
7373
if err != nil {
7474
return err
@@ -92,7 +92,7 @@ func AddGitRemote(ctx context.Context, repo Repository, remoteName, remoteURL st
9292
return err
9393
}
9494

95-
func RemoveGitRemote(ctx context.Context, repo Repository, remoteName string) error {
95+
func GitRemoteRemove(ctx context.Context, repo Repository, remoteName string) error {
9696
releaser, err := globallock.Lock(ctx, getRepoConfigLockKey(repo.RelativePath()))
9797
if err != nil {
9898
return err
@@ -104,8 +104,8 @@ func RemoveGitRemote(ctx context.Context, repo Repository, remoteName string) er
104104
return err
105105
}
106106

107-
// GetRemoteURL returns the url of a specific remote of the repository.
108-
func GetRemoteURL(ctx context.Context, repo Repository, remoteName string) (*giturl.GitURL, error) {
107+
// GitRemoteGetURL returns the url of a specific remote of the repository.
108+
func GitRemoteGetURL(ctx context.Context, repo Repository, remoteName string) (*giturl.GitURL, error) {
109109
addr, err := git.GetRemoteAddress(ctx, repoPath(repo), remoteName)
110110
if err != nil {
111111
return nil, err
@@ -128,10 +128,10 @@ func SetRemoteURL(ctx context.Context, repo Repository, remoteName, remoteURL st
128128
return err
129129
}
130130

131-
// PruneRemote prunes the remote branches that no longer exist in the remote repository.
131+
// GitRemotePrune prunes the remote branches that no longer exist in the remote repository.
132132
// No lock is needed because the remote remoteName will be checked before invoking this function.
133133
// Then it will not update the remote automatically if the remote does not exist.
134-
func PruneRemote(ctx context.Context, repo Repository, remoteName string, timeout time.Duration, stdout, stderr io.Writer) error {
134+
func GitRemotePrune(ctx context.Context, repo Repository, remoteName string, timeout time.Duration, stdout, stderr io.Writer) error {
135135
return git.NewCommand("remote", "prune").AddDynamicArguments(remoteName).
136136
Run(ctx, &git.RunOpts{
137137
Timeout: timeout,
@@ -141,10 +141,10 @@ func PruneRemote(ctx context.Context, repo Repository, remoteName string, timeou
141141
})
142142
}
143143

144-
// UpdateRemotePrune updates the remote branches and prunes the ones that no longer exist in the remote repository.
144+
// GitRemoteUpdatePrune updates the remote branches and prunes the ones that no longer exist in the remote repository.
145145
// No lock is needed because the remote remoteName will be checked before invoking this function.
146146
// Then it will not update the remote automatically if the remote does not exist.
147-
func UpdateRemotePrune(ctx context.Context, repo Repository, remoteName string, timeout time.Duration, stdout, stderr io.Writer) error {
147+
func GitRemoteUpdatePrune(ctx context.Context, repo Repository, remoteName string, timeout time.Duration, stdout, stderr io.Writer) error {
148148
return git.NewCommand("remote", "update", "--prune").AddDynamicArguments(remoteName).
149149
Run(ctx, &git.RunOpts{
150150
Timeout: timeout,

modules/templates/util_misc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ type remoteAddress struct {
144144

145145
func mirrorRemoteAddress(ctx context.Context, m *repo_model.Repository, remoteName string) remoteAddress {
146146
ret := remoteAddress{}
147-
u, err := gitrepo.GetRemoteURL(ctx, m, remoteName)
147+
u, err := gitrepo.GitRemoteGetURL(ctx, m, remoteName)
148148
if err != nil {
149149
log.Error("GetRemoteURL %v", err)
150150
return ret

routers/web/repo/setting/setting.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ func handleSettingsPostMirror(ctx *context.Context) {
259259
return
260260
}
261261

262-
u, err := gitrepo.GetRemoteURL(ctx, ctx.Repo.Repository, pullMirror.GetRemoteName())
262+
u, err := gitrepo.GitRemoteGetURL(ctx, ctx.Repo.Repository, pullMirror.GetRemoteName())
263263
if err != nil {
264264
ctx.Data["Err_MirrorAddress"] = true
265265
handleSettingRemoteAddrError(ctx, err, form)

services/doctor/misc.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,11 @@ func checkEnablePushOptions(ctx context.Context, logger log.Logger, autofix bool
9393
numRepos++
9494

9595
if autofix {
96-
_, err := gitrepo.UpdateGitConfig(ctx, repo, "receive.advertisePushOptions", "true")
96+
err := gitrepo.GitConfigSet(ctx, repo, "receive.advertisePushOptions", "true")
9797
return err
9898
}
9999

100-
value, err := gitrepo.GetGitConfig(ctx, repo, "receive.advertisePushOptions")
100+
value, err := gitrepo.GitConfigGet(ctx, repo, "receive.advertisePushOptions")
101101
if err != nil {
102102
return err
103103
}

services/issue/pull.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ import (
2222
func getMergeBase(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Repository, pr *issues_model.PullRequest, baseBranch, headBranch string) (string, error) {
2323
// Add a temporary remote
2424
tmpRemote := fmt.Sprintf("mergebase-%d-%d", pr.ID, time.Now().UnixNano())
25-
if err := gitrepo.AddGitRemote(ctx, repo, tmpRemote, gitRepo.Path); err != nil {
26-
return "", fmt.Errorf("AddGitRemote: %w", err)
25+
if err := gitrepo.GitRemoteAdd(ctx, repo, tmpRemote, gitRepo.Path); err != nil {
26+
return "", fmt.Errorf("GitRemoteAdd: %w", err)
2727
}
2828
defer func() {
29-
if err := gitrepo.RemoveGitRemote(ctx, repo, tmpRemote); err != nil {
30-
log.Error("getMergeBase: RemoveGitRemote: %v", err)
29+
if err := gitrepo.GitRemoteRemove(ctx, repo, tmpRemote); err != nil {
30+
log.Error("getMergeBase: GitRemoteRemove: %v", err)
3131
}
3232
}()
3333

services/mirror/mirror_pull.go

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -41,25 +41,25 @@ func UpdateAddress(ctx context.Context, m *repo_model.Mirror, addr string) error
4141
remoteName := m.GetRemoteName()
4242
repo := m.GetRepository(ctx)
4343
// Remove old remote
44-
err = gitrepo.RemoveGitRemote(ctx, repo, remoteName)
44+
err = gitrepo.GitRemoteRemove(ctx, repo, remoteName)
4545
if err != nil && !git.IsRemoteNotExistError(err) {
4646
return err
4747
}
4848

49-
err = gitrepo.AddGitRemote(ctx, repo, remoteName, addr, "--mirror=fetch")
49+
err = gitrepo.GitRemoteAdd(ctx, repo, remoteName, addr, "--mirror=fetch")
5050
if err != nil && !git.IsRemoteNotExistError(err) {
5151
return err
5252
}
5353

5454
if m.Repo.HasWiki() {
5555
wikiRemotePath := repo_module.WikiRemoteURL(ctx, addr)
5656
// Remove old remote of wiki
57-
err = gitrepo.RemoveGitRemote(ctx, repo.WikiStorageRepo(), remoteName)
57+
err = gitrepo.GitRemoteRemove(ctx, repo.WikiStorageRepo(), remoteName)
5858
if err != nil && !git.IsRemoteNotExistError(err) {
5959
return err
6060
}
6161

62-
err = gitrepo.AddGitRemote(ctx, repo.WikiStorageRepo(), remoteName, wikiRemotePath, "--mirror=fetch")
62+
err = gitrepo.GitRemoteAdd(ctx, repo.WikiStorageRepo(), remoteName, wikiRemotePath, "--mirror=fetch")
6363
if err != nil && !git.IsRemoteNotExistError(err) {
6464
return err
6565
}
@@ -208,25 +208,7 @@ func pruneBrokenReferences(ctx context.Context,
208208
stderrBuilder.Reset()
209209
stdoutBuilder.Reset()
210210

211-
// check whether the remote still exists before pruning to avoid prune creating a new remote
212-
// this is needed because prune will not fail if the remote does not exist
213-
u, err := gitrepo.GetRemoteURL(ctx, storageRepo, m.GetRemoteName())
214-
if err != nil {
215-
return err
216-
}
217-
if u == nil {
218-
return fmt.Errorf("remote %s does not exist for %srepository %s", m.GetRemoteName(), wiki, storageRepo.RelativePath())
219-
}
220-
221-
fetchConfig, err := gitrepo.GetGitConfig(ctx, storageRepo, "remote.origin.fetch")
222-
if err != nil {
223-
return err
224-
}
225-
if fetchConfig == "" {
226-
return fmt.Errorf("remote %s has no fetch config for %srepository %s", m.GetRemoteName(), wiki, storageRepo.RelativePath())
227-
}
228-
229-
pruneErr := gitrepo.PruneRemote(ctx, storageRepo, m.GetRemoteName(), timeout, stdoutBuilder, stderrBuilder)
211+
pruneErr := gitrepo.GitRemotePrune(ctx, storageRepo, m.GetRemoteName(), timeout, stdoutBuilder, stderrBuilder)
230212
if pruneErr != nil {
231213
stdout := stdoutBuilder.String()
232214
stderr := stderrBuilder.String()
@@ -279,7 +261,7 @@ func runSync(ctx context.Context, m *repo_model.Mirror) ([]*mirrorSyncResult, bo
279261
}
280262
cmd.AddArguments("--tags").AddDynamicArguments(m.GetRemoteName())
281263

282-
remoteURL, remoteErr := gitrepo.GetRemoteURL(ctx, m.Repo, m.GetRemoteName())
264+
remoteURL, remoteErr := gitrepo.GitRemoteGetURL(ctx, m.Repo, m.GetRemoteName())
283265
if remoteErr != nil {
284266
log.Error("SyncMirrors [repo: %-v]: GetRemoteURL Error %v", m.Repo, remoteErr)
285267
return nil, false
@@ -385,7 +367,7 @@ func runSync(ctx context.Context, m *repo_model.Mirror) ([]*mirrorSyncResult, bo
385367

386368
// check whether the remote still exists before pruning to avoid prune creating a new remote
387369
// this is needed because prune will not fail if the remote does not exist
388-
u, err := gitrepo.GetRemoteURL(ctx, m.Repo.WikiStorageRepo(), m.GetRemoteName())
370+
u, err := gitrepo.GitRemoteGetURL(ctx, m.Repo.WikiStorageRepo(), m.GetRemoteName())
389371
if err != nil {
390372
log.Error("SyncMirrors [repo: %-v Wiki]: GetRemoteURL Error %v", m.Repo, err)
391373
return nil, false
@@ -395,7 +377,7 @@ func runSync(ctx context.Context, m *repo_model.Mirror) ([]*mirrorSyncResult, bo
395377
return nil, false
396378
}
397379

398-
fetchConfig, err := gitrepo.GetGitConfig(ctx, m.Repo.WikiStorageRepo(), "remote.origin.fetch")
380+
fetchConfig, err := gitrepo.GitConfigGet(ctx, m.Repo.WikiStorageRepo(), "remote.origin.fetch")
399381
if err != nil {
400382
log.Error("SyncMirrors [repo: %-v Wiki]: GetGitConfig Error %v", m.Repo, err)
401383
return nil, false
@@ -405,7 +387,7 @@ func runSync(ctx context.Context, m *repo_model.Mirror) ([]*mirrorSyncResult, bo
405387
return nil, false
406388
}
407389

408-
if err := gitrepo.UpdateRemotePrune(ctx, m.Repo.WikiStorageRepo(), m.GetRemoteName(),
390+
if err := gitrepo.GitRemoteUpdatePrune(ctx, m.Repo.WikiStorageRepo(), m.GetRemoteName(),
409391
timeout, &stdoutBuilder, &stderrBuilder); err != nil {
410392
stdout := stdoutBuilder.String()
411393
stderr := stderrBuilder.String()
@@ -428,7 +410,7 @@ func runSync(ctx context.Context, m *repo_model.Mirror) ([]*mirrorSyncResult, bo
428410

429411
// check whether the remote still exists before pruning to avoid prune creating a new remote
430412
// this is needed because prune will not fail if the remote does not exist
431-
u, err := gitrepo.GetRemoteURL(ctx, m.Repo.WikiStorageRepo(), m.GetRemoteName())
413+
u, err := gitrepo.GitRemoteGetURL(ctx, m.Repo.WikiStorageRepo(), m.GetRemoteName())
432414
if err != nil {
433415
log.Error("SyncMirrors [repo: %-v Wiki]: GetRemoteURL Error %v", m.Repo, err)
434416
return nil, false
@@ -438,7 +420,7 @@ func runSync(ctx context.Context, m *repo_model.Mirror) ([]*mirrorSyncResult, bo
438420
return nil, false
439421
}
440422

441-
fetchConfig, err := gitrepo.GetGitConfig(ctx, m.Repo.WikiStorageRepo(), "remote.origin.fetch")
423+
fetchConfig, err := gitrepo.GitConfigGet(ctx, m.Repo.WikiStorageRepo(), "remote.origin.fetch")
442424
if err != nil {
443425
log.Error("SyncMirrors [repo: %-v Wiki]: GetGitConfig Error %v", m.Repo, err)
444426
return nil, false
@@ -448,7 +430,7 @@ func runSync(ctx context.Context, m *repo_model.Mirror) ([]*mirrorSyncResult, bo
448430
return nil, false
449431
}
450432

451-
if err = gitrepo.UpdateRemotePrune(ctx, m.Repo.WikiStorageRepo(), m.GetRemoteName(),
433+
if err = gitrepo.GitRemoteUpdatePrune(ctx, m.Repo.WikiStorageRepo(), m.GetRemoteName(),
452434
timeout, &stdoutBuilder, &stderrBuilder); err != nil {
453435
stdout := stdoutBuilder.String()
454436
stderr := stderrBuilder.String()

0 commit comments

Comments
 (0)