mirror of
https://github.com/go-gitea/gitea.git
synced 2025-09-16 20:00:00 +00:00
Merge branch 'lunny/fix_git_config_conflict' of github.com:lunny/gitea into lunny/fix_git_config_conflict
This commit is contained in:
@@ -31,14 +31,21 @@ type GPGSettings struct {
|
|||||||
Format string
|
Format string
|
||||||
}
|
}
|
||||||
|
|
||||||
const PrettyLogFormat = `--pretty=format:%H`
|
const prettyLogFormat = `--pretty=format:%H`
|
||||||
|
|
||||||
// GetAllCommitsCount returns count of all commits in repository
|
// GetAllCommitsCount returns count of all commits in repository
|
||||||
func (repo *Repository) GetAllCommitsCount() (int64, error) {
|
func (repo *Repository) GetAllCommitsCount() (int64, error) {
|
||||||
return AllCommitsCount(repo.Ctx, repo.Path, false)
|
return AllCommitsCount(repo.Ctx, repo.Path, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repo *Repository) ParsePrettyFormatLogToList(logs []byte) ([]*Commit, error) {
|
func (repo *Repository) ShowPrettyFormatLogToList(ctx context.Context, revisionRange string) ([]*Commit, error) {
|
||||||
|
// avoid: ambiguous argument 'refs/a...refs/b': unknown revision or path not in the working tree. Use '--': 'git <command> [<revision>...] -- [<file>...]'
|
||||||
|
logs, _, err := NewCommand("log").AddArguments(prettyLogFormat).
|
||||||
|
AddDynamicArguments(revisionRange).AddArguments("--").
|
||||||
|
RunStdBytes(ctx, &RunOpts{Dir: repo.Path})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
return repo.parsePrettyFormatLogToList(logs)
|
return repo.parsePrettyFormatLogToList(logs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -59,7 +59,7 @@ func (repo *Repository) getCommitByPathWithID(id ObjectID, relpath string) (*Com
|
|||||||
relpath = `\` + relpath
|
relpath = `\` + relpath
|
||||||
}
|
}
|
||||||
|
|
||||||
stdout, _, runErr := NewCommand("log", "-1", PrettyLogFormat).AddDynamicArguments(id.String()).AddDashesAndList(relpath).RunStdString(repo.Ctx, &RunOpts{Dir: repo.Path})
|
stdout, _, runErr := NewCommand("log", "-1", prettyLogFormat).AddDynamicArguments(id.String()).AddDashesAndList(relpath).RunStdString(repo.Ctx, &RunOpts{Dir: repo.Path})
|
||||||
if runErr != nil {
|
if runErr != nil {
|
||||||
return nil, runErr
|
return nil, runErr
|
||||||
}
|
}
|
||||||
@@ -74,7 +74,7 @@ func (repo *Repository) getCommitByPathWithID(id ObjectID, relpath string) (*Com
|
|||||||
|
|
||||||
// GetCommitByPath returns the last commit of relative path.
|
// GetCommitByPath returns the last commit of relative path.
|
||||||
func (repo *Repository) GetCommitByPath(relpath string) (*Commit, error) {
|
func (repo *Repository) GetCommitByPath(relpath string) (*Commit, error) {
|
||||||
stdout, _, runErr := NewCommand("log", "-1", PrettyLogFormat).AddDashesAndList(relpath).RunStdBytes(repo.Ctx, &RunOpts{Dir: repo.Path})
|
stdout, _, runErr := NewCommand("log", "-1", prettyLogFormat).AddDashesAndList(relpath).RunStdBytes(repo.Ctx, &RunOpts{Dir: repo.Path})
|
||||||
if runErr != nil {
|
if runErr != nil {
|
||||||
return nil, runErr
|
return nil, runErr
|
||||||
}
|
}
|
||||||
@@ -94,7 +94,7 @@ func (repo *Repository) commitsByRangeWithTime(id ObjectID, page, pageSize int,
|
|||||||
cmd := NewCommand("log").
|
cmd := NewCommand("log").
|
||||||
AddOptionFormat("--skip=%d", (page-1)*pageSize).
|
AddOptionFormat("--skip=%d", (page-1)*pageSize).
|
||||||
AddOptionFormat("--max-count=%d", pageSize).
|
AddOptionFormat("--max-count=%d", pageSize).
|
||||||
AddArguments(PrettyLogFormat).
|
AddArguments(prettyLogFormat).
|
||||||
AddDynamicArguments(id.String())
|
AddDynamicArguments(id.String())
|
||||||
|
|
||||||
if not != "" {
|
if not != "" {
|
||||||
@@ -141,7 +141,7 @@ func (repo *Repository) searchCommits(id ObjectID, opts SearchCommitsOptions) ([
|
|||||||
}
|
}
|
||||||
|
|
||||||
// create new git log command with limit of 100 commits
|
// create new git log command with limit of 100 commits
|
||||||
cmd := NewCommand("log", "-100", PrettyLogFormat).AddDynamicArguments(id.String())
|
cmd := NewCommand("log", "-100", prettyLogFormat).AddDynamicArguments(id.String())
|
||||||
|
|
||||||
// pretend that all refs along with HEAD were listed on command line as <commis>
|
// pretend that all refs along with HEAD were listed on command line as <commis>
|
||||||
// https://git-scm.com/docs/git-log#Documentation/git-log.txt---all
|
// https://git-scm.com/docs/git-log#Documentation/git-log.txt---all
|
||||||
@@ -175,7 +175,7 @@ func (repo *Repository) searchCommits(id ObjectID, opts SearchCommitsOptions) ([
|
|||||||
// ignore anything not matching a valid sha pattern
|
// ignore anything not matching a valid sha pattern
|
||||||
if id.Type().IsValid(v) {
|
if id.Type().IsValid(v) {
|
||||||
// create new git log command with 1 commit limit
|
// create new git log command with 1 commit limit
|
||||||
hashCmd := NewCommand("log", "-1", PrettyLogFormat)
|
hashCmd := NewCommand("log", "-1", prettyLogFormat)
|
||||||
// add previous arguments except for --grep and --all
|
// add previous arguments except for --grep and --all
|
||||||
addCommonSearchArgs(hashCmd)
|
addCommonSearchArgs(hashCmd)
|
||||||
// add keyword as <commit>
|
// add keyword as <commit>
|
||||||
@@ -410,7 +410,7 @@ func (repo *Repository) CommitsCountBetween(start, end string) (int64, error) {
|
|||||||
|
|
||||||
// commitsBefore the limit is depth, not total number of returned commits.
|
// commitsBefore the limit is depth, not total number of returned commits.
|
||||||
func (repo *Repository) commitsBefore(id ObjectID, limit int) ([]*Commit, error) {
|
func (repo *Repository) commitsBefore(id ObjectID, limit int) ([]*Commit, error) {
|
||||||
cmd := NewCommand("log", PrettyLogFormat)
|
cmd := NewCommand("log", prettyLogFormat)
|
||||||
if limit > 0 {
|
if limit > 0 {
|
||||||
cmd.AddOptionFormat("-%d", limit)
|
cmd.AddOptionFormat("-%d", limit)
|
||||||
}
|
}
|
||||||
@@ -536,7 +536,7 @@ func (repo *Repository) AddLastCommitCache(cacheKey, fullName, sha string) error
|
|||||||
|
|
||||||
// GetCommitBranchStart returns the commit where the branch diverged
|
// GetCommitBranchStart returns the commit where the branch diverged
|
||||||
func (repo *Repository) GetCommitBranchStart(env []string, branch, endCommitID string) (string, error) {
|
func (repo *Repository) GetCommitBranchStart(env []string, branch, endCommitID string) (string, error) {
|
||||||
cmd := NewCommand("log", PrettyLogFormat)
|
cmd := NewCommand("log", prettyLogFormat)
|
||||||
cmd.AddDynamicArguments(endCommitID)
|
cmd.AddDynamicArguments(endCommitID)
|
||||||
|
|
||||||
stdout, _, runErr := cmd.RunStdBytes(repo.Ctx, &RunOpts{
|
stdout, _, runErr := cmd.RunStdBytes(repo.Ctx, &RunOpts{
|
||||||
|
@@ -14,7 +14,7 @@ import (
|
|||||||
"code.gitea.io/gitea/modules/globallock"
|
"code.gitea.io/gitea/modules/globallock"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetGitConfig(ctx context.Context, repo Repository, key string) (string, error) {
|
func GitConfigGet(ctx context.Context, repo Repository, key string) (string, error) {
|
||||||
result, _, err := git.NewCommand("config", "--get").
|
result, _, err := git.NewCommand("config", "--get").
|
||||||
AddDynamicArguments(key).
|
AddDynamicArguments(key).
|
||||||
RunStdString(ctx, &git.RunOpts{Dir: repoPath(repo)})
|
RunStdString(ctx, &git.RunOpts{Dir: repoPath(repo)})
|
||||||
@@ -31,8 +31,8 @@ func getRepoConfigLockKey(repoStoragePath string) string {
|
|||||||
return "repo-config:" + repoStoragePath
|
return "repo-config:" + repoStoragePath
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddGitConfig add a git configuration key to a specific value for the given repository.
|
// GitConfigAdd add a git configuration key to a specific value for the given repository.
|
||||||
func AddGitConfig(ctx context.Context, repo Repository, key, value string) error {
|
func GitConfigAdd(ctx context.Context, repo Repository, key, value string) error {
|
||||||
releaser, err := globallock.Lock(ctx, getRepoConfigLockKey(repo.RelativePath()))
|
releaser, err := globallock.Lock(ctx, getRepoConfigLockKey(repo.RelativePath()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -45,20 +45,20 @@ func AddGitConfig(ctx context.Context, repo Repository, key, value string) error
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateGitConfig updates a git configuration key to a specific value for the given repository.
|
// GitConfigSet updates a git configuration key to a specific value for the given repository.
|
||||||
// If the key does not exist, it will be created.
|
// If the key does not exist, it will be created.
|
||||||
// If the key exists, it will be updated to the new value.
|
// If the key exists, it will be updated to the new value.
|
||||||
func UpdateGitConfig(ctx context.Context, repo Repository, key, value string) (string, error) {
|
func GitConfigSet(ctx context.Context, repo Repository, key, value string) error {
|
||||||
releaser, err := globallock.Lock(ctx, getRepoConfigLockKey(repo.RelativePath()))
|
releaser, err := globallock.Lock(ctx, getRepoConfigLockKey(repo.RelativePath()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return err
|
||||||
}
|
}
|
||||||
defer releaser()
|
defer releaser()
|
||||||
|
|
||||||
value, _, err1 := git.NewCommand("config").
|
_, _, err = git.NewCommand("config").
|
||||||
AddDynamicArguments(key, value).
|
AddDynamicArguments(key, value).
|
||||||
RunStdString(ctx, &git.RunOpts{Dir: repoPath(repo)})
|
RunStdString(ctx, &git.RunOpts{Dir: repoPath(repo)})
|
||||||
return value, err1
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
type RemoteOption string
|
type RemoteOption string
|
||||||
@@ -68,7 +68,7 @@ const (
|
|||||||
RemoteOptionMirrorFetch RemoteOption = "--mirror=fetch"
|
RemoteOptionMirrorFetch RemoteOption = "--mirror=fetch"
|
||||||
)
|
)
|
||||||
|
|
||||||
func AddGitRemote(ctx context.Context, repo Repository, remoteName, remoteURL string, options ...RemoteOption) error {
|
func GitRemoteAdd(ctx context.Context, repo Repository, remoteName, remoteURL string, options ...RemoteOption) error {
|
||||||
releaser, err := globallock.Lock(ctx, getRepoConfigLockKey(repo.RelativePath()))
|
releaser, err := globallock.Lock(ctx, getRepoConfigLockKey(repo.RelativePath()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -92,7 +92,7 @@ func AddGitRemote(ctx context.Context, repo Repository, remoteName, remoteURL st
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func RemoveGitRemote(ctx context.Context, repo Repository, remoteName string) error {
|
func GitRemoteRemove(ctx context.Context, repo Repository, remoteName string) error {
|
||||||
releaser, err := globallock.Lock(ctx, getRepoConfigLockKey(repo.RelativePath()))
|
releaser, err := globallock.Lock(ctx, getRepoConfigLockKey(repo.RelativePath()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -104,8 +104,8 @@ func RemoveGitRemote(ctx context.Context, repo Repository, remoteName string) er
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetRemoteURL returns the url of a specific remote of the repository.
|
// GitRemoteGetURL returns the url of a specific remote of the repository.
|
||||||
func GetRemoteURL(ctx context.Context, repo Repository, remoteName string) (*giturl.GitURL, error) {
|
func GitRemoteGetURL(ctx context.Context, repo Repository, remoteName string) (*giturl.GitURL, error) {
|
||||||
addr, err := git.GetRemoteAddress(ctx, repoPath(repo), remoteName)
|
addr, err := git.GetRemoteAddress(ctx, repoPath(repo), remoteName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -128,10 +128,10 @@ func SetRemoteURL(ctx context.Context, repo Repository, remoteName, remoteURL st
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// PruneRemote prunes the remote branches that no longer exist in the remote repository.
|
// GitRemotePrune prunes the remote branches that no longer exist in the remote repository.
|
||||||
// No lock is needed because the remote remoteName will be checked before invoking this function.
|
// No lock is needed because the remote remoteName will be checked before invoking this function.
|
||||||
// Then it will not update the remote automatically if the remote does not exist.
|
// Then it will not update the remote automatically if the remote does not exist.
|
||||||
func PruneRemote(ctx context.Context, repo Repository, remoteName string, timeout time.Duration, stdout, stderr io.Writer) error {
|
func GitRemotePrune(ctx context.Context, repo Repository, remoteName string, timeout time.Duration, stdout, stderr io.Writer) error {
|
||||||
return git.NewCommand("remote", "prune").AddDynamicArguments(remoteName).
|
return git.NewCommand("remote", "prune").AddDynamicArguments(remoteName).
|
||||||
Run(ctx, &git.RunOpts{
|
Run(ctx, &git.RunOpts{
|
||||||
Timeout: timeout,
|
Timeout: timeout,
|
||||||
@@ -141,10 +141,10 @@ func PruneRemote(ctx context.Context, repo Repository, remoteName string, timeou
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateRemotePrune updates the remote branches and prunes the ones that no longer exist in the remote repository.
|
// GitRemoteUpdatePrune updates the remote branches and prunes the ones that no longer exist in the remote repository.
|
||||||
// No lock is needed because the remote remoteName will be checked before invoking this function.
|
// No lock is needed because the remote remoteName will be checked before invoking this function.
|
||||||
// Then it will not update the remote automatically if the remote does not exist.
|
// Then it will not update the remote automatically if the remote does not exist.
|
||||||
func UpdateRemotePrune(ctx context.Context, repo Repository, remoteName string, timeout time.Duration, stdout, stderr io.Writer) error {
|
func GitRemoteUpdatePrune(ctx context.Context, repo Repository, remoteName string, timeout time.Duration, stdout, stderr io.Writer) error {
|
||||||
return git.NewCommand("remote", "update", "--prune").AddDynamicArguments(remoteName).
|
return git.NewCommand("remote", "update", "--prune").AddDynamicArguments(remoteName).
|
||||||
Run(ctx, &git.RunOpts{
|
Run(ctx, &git.RunOpts{
|
||||||
Timeout: timeout,
|
Timeout: timeout,
|
||||||
|
@@ -144,7 +144,7 @@ type remoteAddress struct {
|
|||||||
|
|
||||||
func mirrorRemoteAddress(ctx context.Context, m *repo_model.Repository, remoteName string) remoteAddress {
|
func mirrorRemoteAddress(ctx context.Context, m *repo_model.Repository, remoteName string) remoteAddress {
|
||||||
ret := remoteAddress{}
|
ret := remoteAddress{}
|
||||||
u, err := gitrepo.GetRemoteURL(ctx, m, remoteName)
|
u, err := gitrepo.GitRemoteGetURL(ctx, m, remoteName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("GetRemoteURL %v", err)
|
log.Error("GetRemoteURL %v", err)
|
||||||
return ret
|
return ret
|
||||||
|
@@ -259,7 +259,7 @@ func handleSettingsPostMirror(ctx *context.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
u, err := gitrepo.GetRemoteURL(ctx, ctx.Repo.Repository, pullMirror.GetRemoteName())
|
u, err := gitrepo.GitRemoteGetURL(ctx, ctx.Repo.Repository, pullMirror.GetRemoteName())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Data["Err_MirrorAddress"] = true
|
ctx.Data["Err_MirrorAddress"] = true
|
||||||
handleSettingRemoteAddrError(ctx, err, form)
|
handleSettingRemoteAddrError(ctx, err, form)
|
||||||
|
@@ -93,11 +93,11 @@ func checkEnablePushOptions(ctx context.Context, logger log.Logger, autofix bool
|
|||||||
numRepos++
|
numRepos++
|
||||||
|
|
||||||
if autofix {
|
if autofix {
|
||||||
_, err := gitrepo.UpdateGitConfig(ctx, repo, "receive.advertisePushOptions", "true")
|
err := gitrepo.GitConfigSet(ctx, repo, "receive.advertisePushOptions", "true")
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
value, err := gitrepo.GetGitConfig(ctx, repo, "receive.advertisePushOptions")
|
value, err := gitrepo.GitConfigGet(ctx, repo, "receive.advertisePushOptions")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@@ -22,12 +22,12 @@ import (
|
|||||||
func getMergeBase(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Repository, pr *issues_model.PullRequest, baseBranch, headBranch string) (string, error) {
|
func getMergeBase(ctx context.Context, repo *repo_model.Repository, gitRepo *git.Repository, pr *issues_model.PullRequest, baseBranch, headBranch string) (string, error) {
|
||||||
// Add a temporary remote
|
// Add a temporary remote
|
||||||
tmpRemote := fmt.Sprintf("mergebase-%d-%d", pr.ID, time.Now().UnixNano())
|
tmpRemote := fmt.Sprintf("mergebase-%d-%d", pr.ID, time.Now().UnixNano())
|
||||||
if err := gitrepo.AddGitRemote(ctx, repo, tmpRemote, gitRepo.Path); err != nil {
|
if err := gitrepo.GitRemoteAdd(ctx, repo, tmpRemote, gitRepo.Path); err != nil {
|
||||||
return "", fmt.Errorf("AddGitRemote: %w", err)
|
return "", fmt.Errorf("GitRemoteAdd: %w", err)
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
if err := gitrepo.RemoveGitRemote(ctx, repo, tmpRemote); err != nil {
|
if err := gitrepo.GitRemoteRemove(ctx, repo, tmpRemote); err != nil {
|
||||||
log.Error("getMergeBase: RemoveGitRemote: %v", err)
|
log.Error("getMergeBase: GitRemoteRemove: %v", err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
@@ -41,12 +41,12 @@ func UpdateAddress(ctx context.Context, m *repo_model.Mirror, addr string) error
|
|||||||
remoteName := m.GetRemoteName()
|
remoteName := m.GetRemoteName()
|
||||||
repo := m.GetRepository(ctx)
|
repo := m.GetRepository(ctx)
|
||||||
// Remove old remote
|
// Remove old remote
|
||||||
err = gitrepo.RemoveGitRemote(ctx, repo, remoteName)
|
err = gitrepo.GitRemoteRemove(ctx, repo, remoteName)
|
||||||
if err != nil && !git.IsRemoteNotExistError(err) {
|
if err != nil && !git.IsRemoteNotExistError(err) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = gitrepo.AddGitRemote(ctx, repo, remoteName, addr, "--mirror=fetch")
|
err = gitrepo.GitRemoteAdd(ctx, repo, remoteName, addr, "--mirror=fetch")
|
||||||
if err != nil && !git.IsRemoteNotExistError(err) {
|
if err != nil && !git.IsRemoteNotExistError(err) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -54,12 +54,12 @@ func UpdateAddress(ctx context.Context, m *repo_model.Mirror, addr string) error
|
|||||||
if m.Repo.HasWiki() {
|
if m.Repo.HasWiki() {
|
||||||
wikiRemotePath := repo_module.WikiRemoteURL(ctx, addr)
|
wikiRemotePath := repo_module.WikiRemoteURL(ctx, addr)
|
||||||
// Remove old remote of wiki
|
// Remove old remote of wiki
|
||||||
err = gitrepo.RemoveGitRemote(ctx, repo.WikiStorageRepo(), remoteName)
|
err = gitrepo.GitRemoteRemove(ctx, repo.WikiStorageRepo(), remoteName)
|
||||||
if err != nil && !git.IsRemoteNotExistError(err) {
|
if err != nil && !git.IsRemoteNotExistError(err) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = gitrepo.AddGitRemote(ctx, repo.WikiStorageRepo(), remoteName, wikiRemotePath, "--mirror=fetch")
|
err = gitrepo.GitRemoteAdd(ctx, repo.WikiStorageRepo(), remoteName, wikiRemotePath, "--mirror=fetch")
|
||||||
if err != nil && !git.IsRemoteNotExistError(err) {
|
if err != nil && !git.IsRemoteNotExistError(err) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -208,25 +208,7 @@ func pruneBrokenReferences(ctx context.Context,
|
|||||||
stderrBuilder.Reset()
|
stderrBuilder.Reset()
|
||||||
stdoutBuilder.Reset()
|
stdoutBuilder.Reset()
|
||||||
|
|
||||||
// check whether the remote still exists before pruning to avoid prune creating a new remote
|
pruneErr := gitrepo.GitRemotePrune(ctx, storageRepo, m.GetRemoteName(), timeout, stdoutBuilder, stderrBuilder)
|
||||||
// this is needed because prune will not fail if the remote does not exist
|
|
||||||
u, err := gitrepo.GetRemoteURL(ctx, storageRepo, m.GetRemoteName())
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if u == nil {
|
|
||||||
return fmt.Errorf("remote %s does not exist for %srepository %s", m.GetRemoteName(), wiki, storageRepo.RelativePath())
|
|
||||||
}
|
|
||||||
|
|
||||||
fetchConfig, err := gitrepo.GetGitConfig(ctx, storageRepo, "remote.origin.fetch")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if fetchConfig == "" {
|
|
||||||
return fmt.Errorf("remote %s has no fetch config for %srepository %s", m.GetRemoteName(), wiki, storageRepo.RelativePath())
|
|
||||||
}
|
|
||||||
|
|
||||||
pruneErr := gitrepo.PruneRemote(ctx, storageRepo, m.GetRemoteName(), timeout, stdoutBuilder, stderrBuilder)
|
|
||||||
if pruneErr != nil {
|
if pruneErr != nil {
|
||||||
stdout := stdoutBuilder.String()
|
stdout := stdoutBuilder.String()
|
||||||
stderr := stderrBuilder.String()
|
stderr := stderrBuilder.String()
|
||||||
@@ -279,7 +261,7 @@ func runSync(ctx context.Context, m *repo_model.Mirror) ([]*mirrorSyncResult, bo
|
|||||||
}
|
}
|
||||||
cmd.AddArguments("--tags").AddDynamicArguments(m.GetRemoteName())
|
cmd.AddArguments("--tags").AddDynamicArguments(m.GetRemoteName())
|
||||||
|
|
||||||
remoteURL, remoteErr := gitrepo.GetRemoteURL(ctx, m.Repo, m.GetRemoteName())
|
remoteURL, remoteErr := gitrepo.GitRemoteGetURL(ctx, m.Repo, m.GetRemoteName())
|
||||||
if remoteErr != nil {
|
if remoteErr != nil {
|
||||||
log.Error("SyncMirrors [repo: %-v]: GetRemoteURL Error %v", m.Repo, remoteErr)
|
log.Error("SyncMirrors [repo: %-v]: GetRemoteURL Error %v", m.Repo, remoteErr)
|
||||||
return nil, false
|
return nil, false
|
||||||
@@ -385,7 +367,7 @@ func runSync(ctx context.Context, m *repo_model.Mirror) ([]*mirrorSyncResult, bo
|
|||||||
|
|
||||||
// check whether the remote still exists before pruning to avoid prune creating a new remote
|
// check whether the remote still exists before pruning to avoid prune creating a new remote
|
||||||
// this is needed because prune will not fail if the remote does not exist
|
// this is needed because prune will not fail if the remote does not exist
|
||||||
u, err := gitrepo.GetRemoteURL(ctx, m.Repo.WikiStorageRepo(), m.GetRemoteName())
|
u, err := gitrepo.GitRemoteGetURL(ctx, m.Repo.WikiStorageRepo(), m.GetRemoteName())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("SyncMirrors [repo: %-v Wiki]: GetRemoteURL Error %v", m.Repo, err)
|
log.Error("SyncMirrors [repo: %-v Wiki]: GetRemoteURL Error %v", m.Repo, err)
|
||||||
return nil, false
|
return nil, false
|
||||||
@@ -395,7 +377,7 @@ func runSync(ctx context.Context, m *repo_model.Mirror) ([]*mirrorSyncResult, bo
|
|||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
|
|
||||||
fetchConfig, err := gitrepo.GetGitConfig(ctx, m.Repo.WikiStorageRepo(), "remote.origin.fetch")
|
fetchConfig, err := gitrepo.GitConfigGet(ctx, m.Repo.WikiStorageRepo(), "remote.origin.fetch")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("SyncMirrors [repo: %-v Wiki]: GetGitConfig Error %v", m.Repo, err)
|
log.Error("SyncMirrors [repo: %-v Wiki]: GetGitConfig Error %v", m.Repo, err)
|
||||||
return nil, false
|
return nil, false
|
||||||
@@ -405,7 +387,7 @@ func runSync(ctx context.Context, m *repo_model.Mirror) ([]*mirrorSyncResult, bo
|
|||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := gitrepo.UpdateRemotePrune(ctx, m.Repo.WikiStorageRepo(), m.GetRemoteName(),
|
if err := gitrepo.GitRemoteUpdatePrune(ctx, m.Repo.WikiStorageRepo(), m.GetRemoteName(),
|
||||||
timeout, &stdoutBuilder, &stderrBuilder); err != nil {
|
timeout, &stdoutBuilder, &stderrBuilder); err != nil {
|
||||||
stdout := stdoutBuilder.String()
|
stdout := stdoutBuilder.String()
|
||||||
stderr := stderrBuilder.String()
|
stderr := stderrBuilder.String()
|
||||||
@@ -428,7 +410,7 @@ func runSync(ctx context.Context, m *repo_model.Mirror) ([]*mirrorSyncResult, bo
|
|||||||
|
|
||||||
// check whether the remote still exists before pruning to avoid prune creating a new remote
|
// check whether the remote still exists before pruning to avoid prune creating a new remote
|
||||||
// this is needed because prune will not fail if the remote does not exist
|
// this is needed because prune will not fail if the remote does not exist
|
||||||
u, err := gitrepo.GetRemoteURL(ctx, m.Repo.WikiStorageRepo(), m.GetRemoteName())
|
u, err := gitrepo.GitRemoteGetURL(ctx, m.Repo.WikiStorageRepo(), m.GetRemoteName())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("SyncMirrors [repo: %-v Wiki]: GetRemoteURL Error %v", m.Repo, err)
|
log.Error("SyncMirrors [repo: %-v Wiki]: GetRemoteURL Error %v", m.Repo, err)
|
||||||
return nil, false
|
return nil, false
|
||||||
@@ -438,7 +420,7 @@ func runSync(ctx context.Context, m *repo_model.Mirror) ([]*mirrorSyncResult, bo
|
|||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
|
|
||||||
fetchConfig, err := gitrepo.GetGitConfig(ctx, m.Repo.WikiStorageRepo(), "remote.origin.fetch")
|
fetchConfig, err := gitrepo.GitConfigGet(ctx, m.Repo.WikiStorageRepo(), "remote.origin.fetch")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("SyncMirrors [repo: %-v Wiki]: GetGitConfig Error %v", m.Repo, err)
|
log.Error("SyncMirrors [repo: %-v Wiki]: GetGitConfig Error %v", m.Repo, err)
|
||||||
return nil, false
|
return nil, false
|
||||||
@@ -448,7 +430,7 @@ func runSync(ctx context.Context, m *repo_model.Mirror) ([]*mirrorSyncResult, bo
|
|||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = gitrepo.UpdateRemotePrune(ctx, m.Repo.WikiStorageRepo(), m.GetRemoteName(),
|
if err = gitrepo.GitRemoteUpdatePrune(ctx, m.Repo.WikiStorageRepo(), m.GetRemoteName(),
|
||||||
timeout, &stdoutBuilder, &stderrBuilder); err != nil {
|
timeout, &stdoutBuilder, &stderrBuilder); err != nil {
|
||||||
stdout := stdoutBuilder.String()
|
stdout := stdoutBuilder.String()
|
||||||
stderr := stderrBuilder.String()
|
stderr := stderrBuilder.String()
|
||||||
|
@@ -30,13 +30,13 @@ var stripExitStatus = regexp.MustCompile(`exit status \d+ - `)
|
|||||||
// AddPushMirrorRemote registers the push mirror remote.
|
// AddPushMirrorRemote registers the push mirror remote.
|
||||||
func AddPushMirrorRemote(ctx context.Context, m *repo_model.PushMirror, addr string) error {
|
func AddPushMirrorRemote(ctx context.Context, m *repo_model.PushMirror, addr string) error {
|
||||||
addRemoteAndConfig := func(storageRepo gitrepo.Repository, addr string) error {
|
addRemoteAndConfig := func(storageRepo gitrepo.Repository, addr string) error {
|
||||||
if err := gitrepo.AddGitRemote(ctx, storageRepo, m.RemoteName, addr, "--mirror=push"); err != nil {
|
if err := gitrepo.GitRemoteAdd(ctx, storageRepo, m.RemoteName, addr, "--mirror=push"); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := gitrepo.AddGitConfig(ctx, storageRepo, "remote."+m.RemoteName+".push", "+refs/heads/*:refs/heads/*"); err != nil {
|
if err := gitrepo.GitConfigAdd(ctx, storageRepo, "remote."+m.RemoteName+".push", "+refs/heads/*:refs/heads/*"); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return gitrepo.AddGitConfig(ctx, storageRepo, "remote."+m.RemoteName+".push", "+refs/tags/*:refs/tags/*")
|
return gitrepo.GitConfigAdd(ctx, storageRepo, "remote."+m.RemoteName+".push", "+refs/tags/*:refs/tags/*")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := addRemoteAndConfig(m.Repo, addr); err != nil {
|
if err := addRemoteAndConfig(m.Repo, addr); err != nil {
|
||||||
@@ -58,12 +58,12 @@ func AddPushMirrorRemote(ctx context.Context, m *repo_model.PushMirror, addr str
|
|||||||
// RemovePushMirrorRemote removes the push mirror remote.
|
// RemovePushMirrorRemote removes the push mirror remote.
|
||||||
func RemovePushMirrorRemote(ctx context.Context, m *repo_model.PushMirror) error {
|
func RemovePushMirrorRemote(ctx context.Context, m *repo_model.PushMirror) error {
|
||||||
_ = m.GetRepository(ctx)
|
_ = m.GetRepository(ctx)
|
||||||
if err := gitrepo.RemoveGitRemote(ctx, m.Repo, m.RemoteName); err != nil {
|
if err := gitrepo.GitRemoteRemove(ctx, m.Repo, m.RemoteName); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if m.Repo.HasWiki() {
|
if m.Repo.HasWiki() {
|
||||||
if err := gitrepo.RemoveGitRemote(ctx, m.Repo.WikiStorageRepo(), m.RemoteName); err != nil {
|
if err := gitrepo.GitRemoteRemove(ctx, m.Repo.WikiStorageRepo(), m.RemoteName); err != nil {
|
||||||
// The wiki remote may not exist
|
// The wiki remote may not exist
|
||||||
log.Warn("Wiki Remote[%d] could not be removed: %v", m.ID, err)
|
log.Warn("Wiki Remote[%d] could not be removed: %v", m.ID, err)
|
||||||
}
|
}
|
||||||
@@ -128,7 +128,7 @@ func runPushSync(ctx context.Context, m *repo_model.PushMirror) error {
|
|||||||
storageRepo = repo.WikiStorageRepo()
|
storageRepo = repo.WikiStorageRepo()
|
||||||
path = repo.WikiPath()
|
path = repo.WikiPath()
|
||||||
}
|
}
|
||||||
remoteURL, err := gitrepo.GetRemoteURL(ctx, storageRepo, m.RemoteName)
|
remoteURL, err := gitrepo.GitRemoteGetURL(ctx, storageRepo, m.RemoteName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("GetRemoteURL(%s) Error %v", path, err)
|
log.Error("GetRemoteURL(%s) Error %v", path, err)
|
||||||
return errors.New("Unexpected error")
|
return errors.New("Unexpected error")
|
||||||
@@ -175,7 +175,7 @@ func runPushSync(ctx context.Context, m *repo_model.PushMirror) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if m.Repo.HasWiki() {
|
if m.Repo.HasWiki() {
|
||||||
u, err := gitrepo.GetRemoteURL(ctx, m.Repo.WikiStorageRepo(), m.RemoteName)
|
u, err := gitrepo.GitRemoteGetURL(ctx, m.Repo.WikiStorageRepo(), m.RemoteName)
|
||||||
if err == nil && u != nil {
|
if err == nil && u != nil {
|
||||||
err := performPush(m.Repo, true)
|
err := performPush(m.Repo, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@@ -35,12 +35,12 @@ func GetCompareInfo(ctx context.Context, baseRepo, headRepo *repo_model.Reposito
|
|||||||
if headGitRepo.Path != baseRepo.RepoPath() {
|
if headGitRepo.Path != baseRepo.RepoPath() {
|
||||||
// Add a temporary remote
|
// Add a temporary remote
|
||||||
tmpRemote = strconv.FormatInt(time.Now().UnixNano(), 10)
|
tmpRemote = strconv.FormatInt(time.Now().UnixNano(), 10)
|
||||||
if err = gitrepo.AddGitRemote(ctx, headRepo, tmpRemote, baseRepo.RepoPath()); err != nil {
|
if err = gitrepo.GitRemoteAdd(ctx, headRepo, tmpRemote, baseRepo.RepoPath()); err != nil {
|
||||||
return nil, fmt.Errorf("AddRemote: %w", err)
|
return nil, fmt.Errorf("AddRemote: %w", err)
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
if err := gitrepo.RemoveGitRemote(ctx, headRepo, tmpRemote); err != nil {
|
if err := gitrepo.GitRemoteRemove(ctx, headRepo, tmpRemote); err != nil {
|
||||||
logger.Error("GetPullRequestInfo: RemoveGitRemote: %v", err)
|
logger.Error("GetPullRequestInfo: GitRemoteRemove: %v", err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
@@ -67,17 +67,9 @@ func GetCompareInfo(ctx context.Context, baseRepo, headRepo *repo_model.Reposito
|
|||||||
|
|
||||||
// We have a common base - therefore we know that ... should work
|
// We have a common base - therefore we know that ... should work
|
||||||
if !fileOnly {
|
if !fileOnly {
|
||||||
// avoid: ambiguous argument 'refs/a...refs/b': unknown revision or path not in the working tree. Use '--': 'git <command> [<revision>...] -- [<file>...]'
|
compareInfo.Commits, err = headGitRepo.ShowPrettyFormatLogToList(ctx, baseCommitID+separator+headBranch)
|
||||||
var logs []byte
|
|
||||||
logs, _, err = git.NewCommand("log").AddArguments(git.PrettyLogFormat).
|
|
||||||
AddDynamicArguments(baseCommitID+separator+headBranch).AddArguments("--").
|
|
||||||
RunStdBytes(ctx, &git.RunOpts{Dir: headGitRepo.Path})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, fmt.Errorf("ShowPrettyFormatLogToList: %w", err)
|
||||||
}
|
|
||||||
compareInfo.Commits, err = headGitRepo.ParsePrettyFormatLogToList(logs)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("parsePrettyFormatLogToList: %w", err)
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
compareInfo.Commits = []*git.Commit{}
|
compareInfo.Commits = []*git.Commit{}
|
||||||
|
@@ -272,13 +272,13 @@ func CleanUpMigrateInfo(ctx context.Context, repo *repo_model.Repository) (*repo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err := gitrepo.RemoveGitRemote(ctx, repo, "origin")
|
err := gitrepo.GitRemoteRemove(ctx, repo, "origin")
|
||||||
if err != nil && !git.IsRemoteNotExistError(err) {
|
if err != nil && !git.IsRemoteNotExistError(err) {
|
||||||
return repo, fmt.Errorf("CleanUpMigrateInfo: %w", err)
|
return repo, fmt.Errorf("CleanUpMigrateInfo: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if repo.HasWiki() {
|
if repo.HasWiki() {
|
||||||
err = gitrepo.RemoveGitRemote(ctx, repo.WikiStorageRepo(), "origin")
|
err = gitrepo.GitRemoteRemove(ctx, repo.WikiStorageRepo(), "origin")
|
||||||
if err != nil && !git.IsRemoteNotExistError(err) {
|
if err != nil && !git.IsRemoteNotExistError(err) {
|
||||||
return repo, fmt.Errorf("cleanUpMigrateGitConfig (wiki): %w", err)
|
return repo, fmt.Errorf("cleanUpMigrateGitConfig (wiki): %w", err)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user