aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2020-10-04 20:09:36 +0200
committerGitHub <noreply@github.com>2020-10-04 20:09:36 +0200
commitd56ce3d5d9f5ef74201a8ee7c25be4820d435b47 (patch)
tree4382550c1e8387b7cb6b13c6dd32508c24e6c4ca
parent9bc2483df054387c1241b2e1644ab7e6e9bc4e9a (diff)
parent1eb13173183cf402e4197be51935a4b3ddacf256 (diff)
downloadgit-bug-d56ce3d5d9f5ef74201a8ee7c25be4820d435b47.tar.gz
Merge pull request #460 from MichaelMure/fix-push
repo: use go-git in more places, fix push
-rw-r--r--api/graphql/graphql_test.go2
-rw-r--r--api/http/git_file_handlers_test.go2
-rw-r--r--bridge/github/export_test.go4
-rw-r--r--bridge/github/import_test.go2
-rw-r--r--bridge/gitlab/export_test.go4
-rw-r--r--bridge/gitlab/import_test.go2
-rw-r--r--bug/bug_actions.go6
-rw-r--r--bug/bug_test.go6
-rw-r--r--bug/operation_test.go2
-rw-r--r--cache/repo_cache_test.go10
-rw-r--r--commands/select/select_test.go2
-rw-r--r--identity/identity_actions.go6
-rw-r--r--repository/git_testing.go6
-rw-r--r--repository/gogit.go30
-rw-r--r--tests/read_bugs_test.go4
15 files changed, 57 insertions, 31 deletions
diff --git a/api/graphql/graphql_test.go b/api/graphql/graphql_test.go
index 45e88e9a..69d96cab 100644
--- a/api/graphql/graphql_test.go
+++ b/api/graphql/graphql_test.go
@@ -14,7 +14,7 @@ import (
)
func TestQueries(t *testing.T) {
- repo := repository.CreateTestRepo(false)
+ repo := repository.CreateGoGitTestRepo(false)
defer repository.CleanupTestRepos(repo)
random_bugs.FillRepoWithSeed(repo, 10, 42)
diff --git a/api/http/git_file_handlers_test.go b/api/http/git_file_handlers_test.go
index 81d97d61..68c1542f 100644
--- a/api/http/git_file_handlers_test.go
+++ b/api/http/git_file_handlers_test.go
@@ -19,7 +19,7 @@ import (
)
func TestGitFileHandlers(t *testing.T) {
- repo := repository.CreateTestRepo(false)
+ repo := repository.CreateGoGitTestRepo(false)
defer repository.CleanupTestRepos(repo)
mrc := cache.NewMultiRepoCache()
diff --git a/bridge/github/export_test.go b/bridge/github/export_test.go
index b160ac7f..5b9a3495 100644
--- a/bridge/github/export_test.go
+++ b/bridge/github/export_test.go
@@ -137,7 +137,7 @@ func TestPushPull(t *testing.T) {
}
// create repo backend
- repo := repository.CreateTestRepo(false)
+ repo := repository.CreateGoGitTestRepo(false)
defer repository.CleanupTestRepos(repo)
backend, err := cache.NewRepoCache(repo)
@@ -209,7 +209,7 @@ func TestPushPull(t *testing.T) {
fmt.Printf("test repository exported in %f seconds\n", time.Since(start).Seconds())
- repoTwo := repository.CreateTestRepo(false)
+ repoTwo := repository.CreateGoGitTestRepo(false)
defer repository.CleanupTestRepos(repoTwo)
// create a second backend
diff --git a/bridge/github/import_test.go b/bridge/github/import_test.go
index f33b30c2..2295806f 100644
--- a/bridge/github/import_test.go
+++ b/bridge/github/import_test.go
@@ -127,7 +127,7 @@ func Test_Importer(t *testing.T) {
},
}
- repo := repository.CreateTestRepo(false)
+ repo := repository.CreateGoGitTestRepo(false)
defer repository.CleanupTestRepos(repo)
backend, err := cache.NewRepoCache(repo)
diff --git a/bridge/gitlab/export_test.go b/bridge/gitlab/export_test.go
index 96dfe1e1..58f3d63c 100644
--- a/bridge/gitlab/export_test.go
+++ b/bridge/gitlab/export_test.go
@@ -142,7 +142,7 @@ func TestPushPull(t *testing.T) {
}
// create repo backend
- repo := repository.CreateTestRepo(false)
+ repo := repository.CreateGoGitTestRepo(false)
defer repository.CleanupTestRepos(repo)
backend, err := cache.NewRepoCache(repo)
@@ -215,7 +215,7 @@ func TestPushPull(t *testing.T) {
fmt.Printf("test repository exported in %f seconds\n", time.Since(start).Seconds())
- repoTwo := repository.CreateTestRepo(false)
+ repoTwo := repository.CreateGoGitTestRepo(false)
defer repository.CleanupTestRepos(repoTwo)
// create a second backend
diff --git a/bridge/gitlab/import_test.go b/bridge/gitlab/import_test.go
index 9a936ae4..db550f08 100644
--- a/bridge/gitlab/import_test.go
+++ b/bridge/gitlab/import_test.go
@@ -76,7 +76,7 @@ func TestImport(t *testing.T) {
},
}
- repo := repository.CreateTestRepo(false)
+ repo := repository.CreateGoGitTestRepo(false)
defer repository.CleanupTestRepos(repo)
backend, err := cache.NewRepoCache(repo)
diff --git a/bug/bug_actions.go b/bug/bug_actions.go
index cb0d0f7d..f99f83ad 100644
--- a/bug/bug_actions.go
+++ b/bug/bug_actions.go
@@ -12,6 +12,7 @@ import (
// Fetch retrieve updates from a remote
// This does not change the local bugs state
func Fetch(repo repository.Repo, remote string) (string, error) {
+ // "refs/bugs/*:refs/remotes/<remote>>/bugs/*"
remoteRefSpec := fmt.Sprintf(bugsRemoteRefPattern, remote)
fetchRefSpec := fmt.Sprintf("%s*:%s*", bugsRefPattern, remoteRefSpec)
@@ -20,7 +21,10 @@ func Fetch(repo repository.Repo, remote string) (string, error) {
// Push update a remote with the local changes
func Push(repo repository.Repo, remote string) (string, error) {
- return repo.PushRefs(remote, bugsRefPattern+"*")
+ // "refs/bugs/*:refs/bugs/*"
+ refspec := fmt.Sprintf("%s*:%s*", bugsRefPattern, bugsRefPattern)
+
+ return repo.PushRefs(remote, refspec)
}
// Pull will do a Fetch + MergeAll
diff --git a/bug/bug_test.go b/bug/bug_test.go
index 400e50f8..ac7da693 100644
--- a/bug/bug_test.go
+++ b/bug/bug_test.go
@@ -117,9 +117,9 @@ func equivalentBug(t *testing.T, expected, actual *Bug) {
}
func TestBugRemove(t *testing.T) {
- repo := repository.CreateTestRepo(false)
- remoteA := repository.CreateTestRepo(true)
- remoteB := repository.CreateTestRepo(true)
+ repo := repository.CreateGoGitTestRepo(false)
+ remoteA := repository.CreateGoGitTestRepo(true)
+ remoteB := repository.CreateGoGitTestRepo(true)
defer repository.CleanupTestRepos(repo, remoteA, remoteB)
err := repo.AddRemote("remoteA", "file://"+remoteA.GetPath())
diff --git a/bug/operation_test.go b/bug/operation_test.go
index 285bdbd6..21ae5eff 100644
--- a/bug/operation_test.go
+++ b/bug/operation_test.go
@@ -79,7 +79,7 @@ func TestMetadata(t *testing.T) {
}
func TestID(t *testing.T) {
- repo := repository.CreateTestRepo(false)
+ repo := repository.CreateGoGitTestRepo(false)
defer repository.CleanupTestRepos(repo)
repos := []repository.ClockedRepo{
diff --git a/cache/repo_cache_test.go b/cache/repo_cache_test.go
index c0f7f189..0037c7bb 100644
--- a/cache/repo_cache_test.go
+++ b/cache/repo_cache_test.go
@@ -12,7 +12,7 @@ import (
)
func TestCache(t *testing.T) {
- repo := repository.CreateTestRepo(false)
+ repo := repository.CreateGoGitTestRepo(false)
defer repository.CleanupTestRepos(repo)
cache, err := NewRepoCache(repo)
@@ -162,9 +162,9 @@ func TestPushPull(t *testing.T) {
}
func TestRemove(t *testing.T) {
- repo := repository.CreateTestRepo(false)
- remoteA := repository.CreateTestRepo(true)
- remoteB := repository.CreateTestRepo(true)
+ repo := repository.CreateGoGitTestRepo(false)
+ remoteA := repository.CreateGoGitTestRepo(true)
+ remoteB := repository.CreateGoGitTestRepo(true)
defer repository.CleanupTestRepos(repo, remoteA, remoteB)
err := repo.AddRemote("remoteA", "file://"+remoteA.GetPath())
@@ -211,7 +211,7 @@ func TestRemove(t *testing.T) {
}
func TestCacheEviction(t *testing.T) {
- repo := repository.CreateTestRepo(false)
+ repo := repository.CreateGoGitTestRepo(false)
repoCache, err := NewRepoCache(repo)
require.NoError(t, err)
repoCache.setCacheSize(2)
diff --git a/commands/select/select_test.go b/commands/select/select_test.go
index ac0d0903..488ab357 100644
--- a/commands/select/select_test.go
+++ b/commands/select/select_test.go
@@ -11,7 +11,7 @@ import (
)
func TestSelect(t *testing.T) {
- repo := repository.CreateTestRepo(false)
+ repo := repository.CreateGoGitTestRepo(false)
defer repository.CleanupTestRepos(repo)
repoCache, err := cache.NewRepoCache(repo)
diff --git a/identity/identity_actions.go b/identity/identity_actions.go
index e33b75f9..2e804533 100644
--- a/identity/identity_actions.go
+++ b/identity/identity_actions.go
@@ -13,6 +13,7 @@ import (
// Fetch retrieve updates from a remote
// This does not change the local identities state
func Fetch(repo repository.Repo, remote string) (string, error) {
+ // "refs/identities/*:refs/remotes/<remote>/identities/*"
remoteRefSpec := fmt.Sprintf(identityRemoteRefPattern, remote)
fetchRefSpec := fmt.Sprintf("%s*:%s*", identityRefPattern, remoteRefSpec)
@@ -21,7 +22,10 @@ func Fetch(repo repository.Repo, remote string) (string, error) {
// Push update a remote with the local changes
func Push(repo repository.Repo, remote string) (string, error) {
- return repo.PushRefs(remote, identityRefPattern+"*")
+ // "refs/identities/*:refs/identities/*"
+ refspec := fmt.Sprintf("%s*:%s*", identityRefPattern, identityRefPattern)
+
+ return repo.PushRefs(remote, refspec)
}
// Pull will do a Fetch + MergeAll
diff --git a/repository/git_testing.go b/repository/git_testing.go
index 7d40bf1f..874cc86c 100644
--- a/repository/git_testing.go
+++ b/repository/git_testing.go
@@ -44,9 +44,9 @@ func CreateTestRepo(bare bool) TestedRepo {
}
func SetupReposAndRemote() (repoA, repoB, remote TestedRepo) {
- repoA = CreateTestRepo(false)
- repoB = CreateTestRepo(false)
- remote = CreateTestRepo(true)
+ repoA = CreateGoGitTestRepo(false)
+ repoB = CreateGoGitTestRepo(false)
+ remote = CreateGoGitTestRepo(true)
remoteAddr := "file://" + remote.GetPath()
diff --git a/repository/gogit.go b/repository/gogit.go
index b907c070..c0179628 100644
--- a/repository/gogit.go
+++ b/repository/gogit.go
@@ -138,10 +138,16 @@ func InitGoGitRepo(path string) (*GoGitRepo, error) {
return nil, err
}
+ k, err := defaultKeyring()
+ if err != nil {
+ return nil, err
+ }
+
return &GoGitRepo{
- r: r,
- path: path + "/.git",
- clocks: make(map[string]lamport.Clock),
+ r: r,
+ path: path + "/.git",
+ clocks: make(map[string]lamport.Clock),
+ keyring: k,
}, nil
}
@@ -152,10 +158,16 @@ func InitBareGoGitRepo(path string) (*GoGitRepo, error) {
return nil, err
}
+ k, err := defaultKeyring()
+ if err != nil {
+ return nil, err
+ }
+
return &GoGitRepo{
- r: r,
- path: path,
- clocks: make(map[string]lamport.Clock),
+ r: r,
+ path: path,
+ clocks: make(map[string]lamport.Clock),
+ keyring: k,
}, nil
}
@@ -276,6 +288,9 @@ func (repo *GoGitRepo) FetchRefs(remote string, refSpec string) (string, error)
RefSpecs: []config.RefSpec{config.RefSpec(refSpec)},
Progress: buf,
})
+ if err == gogit.NoErrAlreadyUpToDate {
+ return "already up-to-date", nil
+ }
if err != nil {
return "", err
}
@@ -292,6 +307,9 @@ func (repo *GoGitRepo) PushRefs(remote string, refSpec string) (string, error) {
RefSpecs: []config.RefSpec{config.RefSpec(refSpec)},
Progress: buf,
})
+ if err == gogit.NoErrAlreadyUpToDate {
+ return "already up-to-date", nil
+ }
if err != nil {
return "", err
}
diff --git a/tests/read_bugs_test.go b/tests/read_bugs_test.go
index 4fd3943a..e6264eba 100644
--- a/tests/read_bugs_test.go
+++ b/tests/read_bugs_test.go
@@ -9,7 +9,7 @@ import (
)
func TestReadBugs(t *testing.T) {
- repo := repository.CreateTestRepo(false)
+ repo := repository.CreateGoGitTestRepo(false)
defer repository.CleanupTestRepos(repo)
random_bugs.FillRepoWithSeed(repo, 15, 42)
@@ -23,7 +23,7 @@ func TestReadBugs(t *testing.T) {
}
func benchmarkReadBugs(bugNumber int, t *testing.B) {
- repo := repository.CreateTestRepo(false)
+ repo := repository.CreateGoGitTestRepo(false)
defer repository.CleanupTestRepos(repo)
random_bugs.FillRepoWithSeed(repo, bugNumber, 42)