mirror of
https://github.com/MichaelMure/git-bug.git
synced 2024-12-15 02:01:43 +03:00
refactor: use namespace instead of application of applicationName
This commit is contained in:
parent
e29f58bf85
commit
e120fdb97e
@ -14,7 +14,7 @@ import (
|
|||||||
"github.com/MichaelMure/git-bug/util/interrupt"
|
"github.com/MichaelMure/git-bug/util/interrupt"
|
||||||
)
|
)
|
||||||
|
|
||||||
const gitBugApplicationName = "git-bug"
|
const gitBugNamespace = "git-bug"
|
||||||
|
|
||||||
// Env is the environment of a command
|
// Env is the environment of a command
|
||||||
type Env struct {
|
type Env struct {
|
||||||
@ -56,7 +56,7 @@ func loadRepo(env *Env) func(*cobra.Command, []string) error {
|
|||||||
return fmt.Errorf("unable to get the current working directory: %q", err)
|
return fmt.Errorf("unable to get the current working directory: %q", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
env.repo, err = repository.OpenGoGitRepo(cwd, gitBugApplicationName, []repository.ClockLoader{bug.ClockLoader})
|
env.repo, err = repository.OpenGoGitRepo(cwd, gitBugNamespace, []repository.ClockLoader{bug.ClockLoader})
|
||||||
if err == repository.ErrNotARepo {
|
if err == repository.ErrNotARepo {
|
||||||
return fmt.Errorf("%s must be run from within a git repo", rootCommandName)
|
return fmt.Errorf("%s must be run from within a git repo", rootCommandName)
|
||||||
}
|
}
|
||||||
|
@ -336,15 +336,15 @@ func Read(repo repository.ClockedRepo, id entity.Id) (*ProjectConfig, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Example_entity() {
|
func Example_entity() {
|
||||||
const gitBugApplicationName = "git-bug"
|
const gitBugNamespace = "git-bug"
|
||||||
// Note: this example ignore errors for readability
|
// Note: this example ignore errors for readability
|
||||||
// Note: variable names get a little confusing as we are simulating both side in the same function
|
// Note: variable names get a little confusing as we are simulating both side in the same function
|
||||||
|
|
||||||
// Let's start by defining two git repository and connecting them as remote
|
// Let's start by defining two git repository and connecting them as remote
|
||||||
repoRenePath, _ := os.MkdirTemp("", "")
|
repoRenePath, _ := os.MkdirTemp("", "")
|
||||||
repoIsaacPath, _ := os.MkdirTemp("", "")
|
repoIsaacPath, _ := os.MkdirTemp("", "")
|
||||||
repoRene, _ := repository.InitGoGitRepo(repoRenePath, gitBugApplicationName)
|
repoRene, _ := repository.InitGoGitRepo(repoRenePath, gitBugNamespace)
|
||||||
repoIsaac, _ := repository.InitGoGitRepo(repoIsaacPath, gitBugApplicationName)
|
repoIsaac, _ := repository.InitGoGitRepo(repoIsaacPath, gitBugNamespace)
|
||||||
_ = repoRene.AddRemote("origin", repoIsaacPath)
|
_ = repoRene.AddRemote("origin", repoIsaacPath)
|
||||||
_ = repoIsaac.AddRemote("origin", repoRenePath)
|
_ = repoIsaac.AddRemote("origin", repoRenePath)
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ import (
|
|||||||
// This program will randomly generate a collection of bugs in the repository
|
// This program will randomly generate a collection of bugs in the repository
|
||||||
// of the current path
|
// of the current path
|
||||||
func main() {
|
func main() {
|
||||||
const gitBugApplicationName = "git-bug"
|
const gitBugNamespace = "git-bug"
|
||||||
|
|
||||||
dir, err := os.Getwd()
|
dir, err := os.Getwd()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -22,7 +22,7 @@ func main() {
|
|||||||
bug.ClockLoader,
|
bug.ClockLoader,
|
||||||
}
|
}
|
||||||
|
|
||||||
repo, err := repository.OpenGoGitRepo(dir, gitBugApplicationName, loaders)
|
repo, err := repository.OpenGoGitRepo(dir, gitBugNamespace, loaders)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -50,11 +50,11 @@ type GoGitRepo struct {
|
|||||||
localStorage billy.Filesystem
|
localStorage billy.Filesystem
|
||||||
}
|
}
|
||||||
|
|
||||||
// OpenGoGitRepo opens an already existing repo at the given path and with
|
// OpenGoGitRepo opens an already existing repo at the given path and
|
||||||
// the specified application name. Given a repository path of "~/myrepo"
|
// with the specified LocalStorage namespace. Given a repository path
|
||||||
// and an application name of "git-bug", local storage for the application
|
// of "~/myrepo" and a namespace of "git-bug", local storage for the
|
||||||
// will be configured at "~/myrepo/.git/git-bug".
|
// GoGitRepo will be configured at "~/myrepo/.git/git-bug".
|
||||||
func OpenGoGitRepo(path, application string, clockLoaders []ClockLoader) (*GoGitRepo, error) {
|
func OpenGoGitRepo(path, namespace string, clockLoaders []ClockLoader) (*GoGitRepo, error) {
|
||||||
path, err := detectGitPath(path)
|
path, err := detectGitPath(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -76,7 +76,7 @@ func OpenGoGitRepo(path, application string, clockLoaders []ClockLoader) (*GoGit
|
|||||||
clocks: make(map[string]lamport.Clock),
|
clocks: make(map[string]lamport.Clock),
|
||||||
indexes: make(map[string]bleve.Index),
|
indexes: make(map[string]bleve.Index),
|
||||||
keyring: k,
|
keyring: k,
|
||||||
localStorage: osfs.New(filepath.Join(path, application)),
|
localStorage: osfs.New(filepath.Join(path, namespace)),
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, loader := range clockLoaders {
|
for _, loader := range clockLoaders {
|
||||||
@ -98,11 +98,11 @@ func OpenGoGitRepo(path, application string, clockLoaders []ClockLoader) (*GoGit
|
|||||||
return repo, nil
|
return repo, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// InitGoGitRepo creates a new empty git repo at the given path and with
|
// InitGoGitRepo creates a new empty git repo at the given path and
|
||||||
// the specified application name. Given a repository path of "~/myrepo"
|
// with the specified LocalStorage namespace. Given a repository path
|
||||||
// and an application name of "git-bug", local storage for the application
|
// of "~/myrepo" and a namespace of "git-bug", local storage for the
|
||||||
// will be configured at "~/myrepo/.git/git-bug".
|
// GoGitRepo will be configured at "~/myrepo/.git/git-bug".
|
||||||
func InitGoGitRepo(path, application string) (*GoGitRepo, error) {
|
func InitGoGitRepo(path, namespace string) (*GoGitRepo, error) {
|
||||||
r, err := gogit.PlainInit(path, false)
|
r, err := gogit.PlainInit(path, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -119,15 +119,15 @@ func InitGoGitRepo(path, application string) (*GoGitRepo, error) {
|
|||||||
clocks: make(map[string]lamport.Clock),
|
clocks: make(map[string]lamport.Clock),
|
||||||
indexes: make(map[string]bleve.Index),
|
indexes: make(map[string]bleve.Index),
|
||||||
keyring: k,
|
keyring: k,
|
||||||
localStorage: osfs.New(filepath.Join(path, ".git", application)),
|
localStorage: osfs.New(filepath.Join(path, ".git", namespace)),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// InitBareGoGitRepo creates a new --bare empty git repo at the given path
|
// InitBareGoGitRepo creates a new --bare empty git repo at the given
|
||||||
// and with the specified application name. Given a repository path of
|
// path and with the specified LocalStorage namespace. Given a repository
|
||||||
// "~/myrepo" and an application name of "git-bug", local storage for the
|
// path of "~/myrepo" and a namespace of "git-bug", local storage for the
|
||||||
// application will be configured at "~/myrepo/.git/git-bug".
|
// GoGitRepo will be configured at "~/myrepo/.git/git-bug".
|
||||||
func InitBareGoGitRepo(path, application string) (*GoGitRepo, error) {
|
func InitBareGoGitRepo(path, namespace string) (*GoGitRepo, error) {
|
||||||
r, err := gogit.PlainInit(path, true)
|
r, err := gogit.PlainInit(path, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -144,7 +144,7 @@ func InitBareGoGitRepo(path, application string) (*GoGitRepo, error) {
|
|||||||
clocks: make(map[string]lamport.Clock),
|
clocks: make(map[string]lamport.Clock),
|
||||||
indexes: make(map[string]bleve.Index),
|
indexes: make(map[string]bleve.Index),
|
||||||
keyring: k,
|
keyring: k,
|
||||||
localStorage: osfs.New(filepath.Join(path, application)),
|
localStorage: osfs.New(filepath.Join(path, namespace)),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -306,7 +306,7 @@ func (repo *GoGitRepo) GetRemotes() (map[string]string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// LocalStorage returns a billy.Filesystem giving access to
|
// LocalStorage returns a billy.Filesystem giving access to
|
||||||
// $RepoPath/.git/$ApplicationName.
|
// $RepoPath/.git/$Namespace.
|
||||||
func (repo *GoGitRepo) LocalStorage() billy.Filesystem {
|
func (repo *GoGitRepo) LocalStorage() billy.Filesystem {
|
||||||
return repo.localStorage
|
return repo.localStorage
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
"github.com/99designs/keyring"
|
"github.com/99designs/keyring"
|
||||||
)
|
)
|
||||||
|
|
||||||
const testApplicationName = "git-bug"
|
const namespace = "git-bug"
|
||||||
|
|
||||||
// This is intended for testing only
|
// This is intended for testing only
|
||||||
|
|
||||||
@ -25,7 +25,7 @@ func CreateGoGitTestRepo(bare bool) TestedRepo {
|
|||||||
creator = InitGoGitRepo
|
creator = InitGoGitRepo
|
||||||
}
|
}
|
||||||
|
|
||||||
repo, err := creator(dir, testApplicationName)
|
repo, err := creator(dir, namespace)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user