From 1a0c86a12d68a2f0ee99cbff535c82e07b735108 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Mur=C3=A9?= Date: Sun, 4 Oct 2020 19:56:16 +0200 Subject: [PATCH 1/2] repo: use go-git in more places, fix push --- api/graphql/graphql_test.go | 2 +- api/http/git_file_handlers_test.go | 2 +- bridge/github/export_test.go | 4 ++-- bridge/github/import_test.go | 2 +- bridge/gitlab/export_test.go | 4 ++-- bridge/gitlab/import_test.go | 2 +- bug/bug_actions.go | 6 +++++- bug/bug_test.go | 6 +++--- bug/operation_test.go | 2 +- cache/repo_cache_test.go | 10 +++++----- commands/select/select_test.go | 2 +- identity/identity_actions.go | 6 +++++- repository/git_testing.go | 6 +++--- repository/gogit.go | 6 ++++++ tests/read_bugs_test.go | 4 ++-- 15 files changed, 39 insertions(+), 25 deletions(-) diff --git a/api/graphql/graphql_test.go b/api/graphql/graphql_test.go index 45e88e9af8f45666c27f6d3bb0a41c5f49ccbb3e..69d96cab7a5c69e7046406c11c177d69b6d560a4 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 81d97d61c52636c75a47c830bea7fc7dcb4d7960..68c1542fdbfa96970b2ef7fd6b2307d0256d96f0 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 b160ac7f320af1f402b3bbf0ab88a653154a54fc..5b9a349581b1d90e94c46e74adc8865cc6a909c6 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 f33b30c28bb4f74b5b473134177c88cedf729241..2295806f1689c5f1e03dbd8b34154a86209e5f5b 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 96dfe1e1b2e40f979d73a5d7b496bb8c7a304d0a..58f3d63cd995d7ec098ed7b293c27dba12201fc3 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 9a936ae4807890198d7b765bda7ae246d9fc416e..db550f081a68914f5bb0c08889c0dcdc2cac64c9 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 cb0d0f7df9ce8d113fbcd2a92d96b8860a0561d7..f99f83ad8013cca44bf80ccfbaad3b33eef7309e 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/>/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 400e50f8711e2dbe182f7565932e9ce774045b78..ac7da6937ed9f1400ee6cb02b17a59c68aecc561 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 285bdbd60aa4729d73b2776dd51c84662639a182..21ae5eff5358e0fd43dce6201715c12923ceb879 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 c0f7f18996eb292541f9d8c86b7e403e76ae6a76..0037c7bbaf619140005d4c4fda4149aa74757059 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 ac0d0903da61725f8c388177c84373e14c1d66de..488ab35759726892362e7242fe66d3a8d7d231f9 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 e33b75f9675a679d93e630fd5b84d7c04cfdd43b..2e804533cae00f6770e1ad9310fff02e1a2de49d 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//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 7d40bf1fd7a329bf28f6039809fc1b0a62065cc0..874cc86ceabd59fe0fbc977e6a13cd88bcd219d3 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 b907c070ee49e7bef96c6f2eda7dfe6067bbc74b..8fb7c52a33bec7083128d8d555b63015c6404918 100644 --- a/repository/gogit.go +++ b/repository/gogit.go @@ -276,6 +276,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 +295,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 4fd3943ab12c7c5279cfe4053e5ac26f341a90e7..e6264ebac4c6e96473675c24dc46770390721b24 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) From 1eb13173183cf402e4197be51935a4b3ddacf256 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Mur=C3=A9?= Date: Sun, 4 Oct 2020 20:03:44 +0200 Subject: [PATCH 2/2] repo: fix missing keyring on the go-git repo --- repository/gogit.go | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/repository/gogit.go b/repository/gogit.go index 8fb7c52a33bec7083128d8d555b63015c6404918..c0179628b60525e8d0f6dfba381144c35f166e33 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 }