diff options
author | Michael Muré <michael.mure@consensys.net> | 2019-02-03 19:55:35 +0100 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2019-03-01 22:40:23 +0100 |
commit | 328a4e5abf3ec8ea41f89575fcfb83cf9f086c80 (patch) | |
tree | 29ce99a1cb244badd74acb61d2b251e56fd1643f /identity/identity.go | |
parent | 56c6147eb6012252cf0b723b9eb6d1e841fc2f94 (diff) | |
download | git-bug-328a4e5abf3ec8ea41f89575fcfb83cf9f086c80.tar.gz |
identity: wip push/pull
Diffstat (limited to 'identity/identity.go')
-rw-r--r-- | identity/identity.go | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/identity/identity.go b/identity/identity.go index 2dafb353..3877e346 100644 --- a/identity/identity.go +++ b/identity/identity.go @@ -4,14 +4,17 @@ package identity import ( "encoding/json" "fmt" + "strings" + + "github.com/pkg/errors" "github.com/MichaelMure/git-bug/repository" "github.com/MichaelMure/git-bug/util/git" "github.com/MichaelMure/git-bug/util/lamport" - "github.com/pkg/errors" ) const identityRefPattern = "refs/identities/" +const identityRemoteRefPattern = "refs/remotes/%s/identities/" const versionEntryName = "version" const identityConfigKey = "git-bug.identity" @@ -62,9 +65,22 @@ func (i *Identity) UnmarshalJSON(data []byte) error { panic("identity should be loaded with identity.UnmarshalJSON") } -// Read load an Identity from the identities data available in git -func Read(repo repository.Repo, id string) (*Identity, error) { +// ReadLocal load a local Identity from the identities data available in git +func ReadLocal(repo repository.Repo, id string) (*Identity, error) { ref := fmt.Sprintf("%s%s", identityRefPattern, id) + return read(repo, ref) +} + +// ReadRemote load a remote Identity from the identities data available in git +func ReadRemote(repo repository.Repo, remote string, id string) (*Identity, error) { + ref := fmt.Sprintf(identityRemoteRefPattern, remote) + id + return read(repo, ref) +} + +// read will load and parse an identity frdm git +func read(repo repository.Repo, ref string) (*Identity, error) { + refSplit := strings.Split(ref, "/") + id := refSplit[len(refSplit)-1] hashes, err := repo.ListCommits(ref) @@ -162,7 +178,7 @@ func GetUserIdentity(repo repository.Repo) (*Identity, error) { id = val } - return Read(repo, id) + return ReadLocal(repo, id) } func (i *Identity) AddVersion(version *Version) { |