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/git.go | |
parent | 28adf41af6a5c0f4b19875912d056b03ea6710f8 (diff) | |
download | git-bug-bca9ae82745ffd619fd321f4200016c184849f94.tar.gz |
repo: more work towards RepoStorage
Diffstat (limited to 'repository/git.go')
-rw-r--r-- | repository/git.go | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/repository/git.go b/repository/git.go index 504cdd89..8c319285 100644 --- a/repository/git.go +++ b/repository/git.go @@ -4,10 +4,15 @@ package repository import ( "bytes" "fmt" + "os" "path" + "path/filepath" "strings" "sync" + "github.com/go-git/go-billy/v5" + "github.com/go-git/go-billy/v5/osfs" + "github.com/MichaelMure/git-bug/util/lamport" ) @@ -174,6 +179,11 @@ func (repo *GitRepo) GetRemotes() (map[string]string, error) { return remotes, nil } +// LocalStorage return a billy.Filesystem giving access to $RepoPath/.git/git-bug +func (repo *GitRepo) LocalStorage() billy.Filesystem { + return osfs.New(repo.path) +} + // FetchRefs fetch git refs from a remote func (repo *GitRepo) FetchRefs(remote, refSpec string) (string, error) { stdout, err := repo.runGitCommand("fetch", remote, refSpec) @@ -408,3 +418,16 @@ func (repo *GitRepo) AddRemote(name string, url string) error { return err } + +// GetLocalRemote return the URL to use to add this repo as a local remote +func (repo *GitRepo) GetLocalRemote() string { + return repo.path +} + +// EraseFromDisk delete this repository entirely from the disk +func (repo *GitRepo) EraseFromDisk() error { + path := filepath.Clean(strings.TrimSuffix(repo.path, string(filepath.Separator)+".git")) + + // fmt.Println("Cleaning repo:", path) + return os.RemoveAll(path) +} |