diff options
author | Michael Muré <batolettre@gmail.com> | 2020-12-01 21:19:23 +0100 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2020-12-05 21:41:10 +0100 |
commit | bca9ae82745ffd619fd321f4200016c184849f94 (patch) | |
tree | 6223d23c3e865bd2d29ea888d944a57467f2b44d /repository/gogit.go | |
parent | 28adf41af6a5c0f4b19875912d056b03ea6710f8 (diff) | |
download | git-bug-bca9ae82745ffd619fd321f4200016c184849f94.tar.gz |
repo: more work towards RepoStorage
Diffstat (limited to 'repository/gogit.go')
-rw-r--r-- | repository/gogit.go | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/repository/gogit.go b/repository/gogit.go index 45906ea4..874885db 100644 --- a/repository/gogit.go +++ b/repository/gogit.go @@ -13,7 +13,8 @@ import ( "sync" "time" - "github.com/go-git/go-billy" + "github.com/go-git/go-billy/v5" + "github.com/go-git/go-billy/v5/osfs" gogit "github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5/config" "github.com/go-git/go-git/v5/plumbing" @@ -24,6 +25,7 @@ import ( ) var _ ClockedRepo = &GoGitRepo{} +var _ TestedRepo = &GoGitRepo{} type GoGitRepo struct { r *gogit.Repository @@ -33,12 +35,6 @@ type GoGitRepo struct { clocks map[string]lamport.Clock keyring Keyring - RepoStorage -} - -type RepoStorage interface { - // Storage returns a billy.Filesystem giving access to $RepoPath/.git/git-bug - Storage() billy.Filesystem } func NewGoGitRepo(path string, clockLoaders []ClockLoader) (*GoGitRepo, error) { @@ -202,11 +198,6 @@ func (repo *GoGitRepo) Keyring() Keyring { return repo.keyring } -// GetPath returns the path to the repo. -func (repo *GoGitRepo) GetPath() string { - return repo.path -} - // GetUserName returns the name the the user has used to configure git func (repo *GoGitRepo) GetUserName() (string, error) { return repo.AnyConfig().ReadString("user.name") @@ -277,6 +268,11 @@ func (repo *GoGitRepo) GetRemotes() (map[string]string, error) { return result, nil } +// LocalStorage return a billy.Filesystem giving access to $RepoPath/.git/git-bug +func (repo *GoGitRepo) LocalStorage() billy.Filesystem { + return osfs.New(repo.path) +} + // FetchRefs fetch git refs from a remote func (repo *GoGitRepo) FetchRefs(remote string, refSpec string) (string, error) { buf := bytes.NewBuffer(nil) @@ -660,3 +656,16 @@ func (repo *GoGitRepo) AddRemote(name string, url string) error { return err } + +// GetLocalRemote return the URL to use to add this repo as a local remote +func (repo *GoGitRepo) GetLocalRemote() string { + return repo.path +} + +// EraseFromDisk delete this repository entirely from the disk +func (repo *GoGitRepo) EraseFromDisk() error { + path := filepath.Clean(strings.TrimSuffix(repo.path, string(filepath.Separator)+".git")) + + // fmt.Println("Cleaning repo:", path) + return os.RemoveAll(path) +} |