diff options
author | Vincent Tiu <46623413+Invincibot@users.noreply.github.com> | 2020-07-09 20:40:44 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-09 14:40:44 +0200 |
commit | f3304bdc1c215e733b9a2ee6a228e64f663c2b09 (patch) | |
tree | 44e21d3922b270dfe92a49361567775e684a292a /repository | |
parent | de062a78ece6a33cc44d8bd3372d814b288ce916 (diff) | |
download | git-bug-f3304bdc1c215e733b9a2ee6a228e64f663c2b09.tar.gz |
Add functionality to remove bugs from a local repository. (#423)
Add functionality to remove bugs from a local repository.
This adds a function to remove git references in the repo and another one to remove bugs.
Diffstat (limited to 'repository')
-rw-r--r-- | repository/git.go | 7 | ||||
-rw-r--r-- | repository/mock_repo.go | 5 | ||||
-rw-r--r-- | repository/repo.go | 3 | ||||
-rw-r--r-- | repository/repo_testing.go | 7 |
4 files changed, 20 insertions, 2 deletions
diff --git a/repository/git.go b/repository/git.go index 22055dbb..3d756324 100644 --- a/repository/git.go +++ b/repository/git.go @@ -282,6 +282,13 @@ func (repo *GitRepo) UpdateRef(ref string, hash Hash) error { return err } +// RemoveRef will remove a Git reference +func (repo *GitRepo) RemoveRef(ref string) error { + _, err := repo.runGitCommand("update-ref", "-d", ref) + + return err +} + // ListRefs will return a list of Git ref matching the given refspec func (repo *GitRepo) ListRefs(refspec string) ([]string, error) { stdout, err := repo.runGitCommand("for-each-ref", "--format=%(refname)", refspec) diff --git a/repository/mock_repo.go b/repository/mock_repo.go index df2af14b..576e984e 100644 --- a/repository/mock_repo.go +++ b/repository/mock_repo.go @@ -134,6 +134,11 @@ func (r *mockRepoForTest) UpdateRef(ref string, hash Hash) error { return nil } +func (r *mockRepoForTest) RemoveRef(ref string) error { + delete(r.refs, ref) + return nil +} + func (r *mockRepoForTest) RefExist(ref string) (bool, error) { _, exist := r.refs[ref] return exist, nil diff --git a/repository/repo.go b/repository/repo.go index 8c76af5e..30d95806 100644 --- a/repository/repo.go +++ b/repository/repo.go @@ -83,6 +83,9 @@ type Repo interface { // UpdateRef will create or update a Git reference UpdateRef(ref string, hash Hash) error + // RemoveRef will remove a Git reference + RemoveRef(ref string) error + // ListRefs will return a list of Git ref matching the given refspec ListRefs(refspec string) ([]string, error) diff --git a/repository/repo_testing.go b/repository/repo_testing.go index 34312011..28eb9a21 100644 --- a/repository/repo_testing.go +++ b/repository/repo_testing.go @@ -145,7 +145,7 @@ func RepoTest(t *testing.T, creator RepoCreator, cleaner RepoCleaner) { ls, err := repo.ListRefs("refs/bugs") require.NoError(t, err) - assert.Equal(t, []string{"refs/bugs/ref1"}, ls) + assert.ElementsMatch(t, []string{"refs/bugs/ref1"}, ls) err = repo.CopyRef("refs/bugs/ref1", "refs/bugs/ref2") require.NoError(t, err) @@ -156,7 +156,7 @@ func RepoTest(t *testing.T, creator RepoCreator, cleaner RepoCleaner) { commits, err := repo.ListCommits("refs/bugs/ref2") require.NoError(t, err) - assert.Equal(t, []Hash{commit1, commit2}, commits) + assert.ElementsMatch(t, []Hash{commit1, commit2}, commits) // Graph @@ -166,6 +166,9 @@ func RepoTest(t *testing.T, creator RepoCreator, cleaner RepoCleaner) { ancestorHash, err := repo.FindCommonAncestor(commit2, commit3) require.NoError(t, err) assert.Equal(t, commit1, ancestorHash) + + err = repo.RemoveRef("refs/bugs/ref1") + require.NoError(t, err) }) t.Run("Local config", func(t *testing.T) { |