From 06d9c6872655b85f1a47599add92d49d570e7b2e Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Wed, 16 Jan 2019 21:23:49 +0100 Subject: identity: implement the loading from git --- bug/bug.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'bug/bug.go') diff --git a/bug/bug.go b/bug/bug.go index b6d09c50..be3e2661 100644 --- a/bug/bug.go +++ b/bug/bug.go @@ -113,13 +113,6 @@ func ReadRemoteBug(repo repository.ClockedRepo, remote string, id string) (*Bug, // readBug will read and parse a Bug from git func readBug(repo repository.ClockedRepo, ref string) (*Bug, error) { - hashes, err := repo.ListCommits(ref) - - // TODO: this is not perfect, it might be a command invoke error - if err != nil { - return nil, ErrBugNotExist - } - refSplit := strings.Split(ref, "/") id := refSplit[len(refSplit)-1] @@ -127,6 +120,13 @@ func readBug(repo repository.ClockedRepo, ref string) (*Bug, error) { return nil, fmt.Errorf("invalid ref length") } + hashes, err := repo.ListCommits(ref) + + // TODO: this is not perfect, it might be a command invoke error + if err != nil { + return nil, ErrBugNotExist + } + bug := Bug{ id: id, } -- cgit From 56c6147eb6012252cf0b723b9eb6d1e841fc2f94 Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Fri, 1 Feb 2019 12:22:00 +0100 Subject: identity: more refactoring progress --- bug/bug.go | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'bug/bug.go') diff --git a/bug/bug.go b/bug/bug.go index be3e2661..aec9a12e 100644 --- a/bug/bug.go +++ b/bug/bug.go @@ -6,6 +6,8 @@ import ( "fmt" "strings" + "github.com/MichaelMure/git-bug/identity" + "github.com/MichaelMure/git-bug/repository" "github.com/MichaelMure/git-bug/util/git" "github.com/MichaelMure/git-bug/util/lamport" @@ -217,6 +219,13 @@ func readBug(repo repository.ClockedRepo, ref string) (*Bug, error) { bug.packs = append(bug.packs, *opp) } + // Make sure that the identities are properly loaded + resolver := identity.NewSimpleResolver(repo) + err = bug.EnsureIdentities(resolver) + if err != nil { + return nil, err + } + return &bug, nil } -- cgit From 328a4e5abf3ec8ea41f89575fcfb83cf9f086c80 Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Sun, 3 Feb 2019 19:55:35 +0100 Subject: identity: wip push/pull --- bug/bug.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'bug/bug.go') diff --git a/bug/bug.go b/bug/bug.go index aec9a12e..1717dd66 100644 --- a/bug/bug.go +++ b/bug/bug.go @@ -6,12 +6,12 @@ import ( "fmt" "strings" - "github.com/MichaelMure/git-bug/identity" + "github.com/pkg/errors" + "github.com/MichaelMure/git-bug/identity" "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 bugsRefPattern = "refs/bugs/" -- cgit From 21048e785d976a04e26798e4a385ee675c95b88f Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Wed, 6 Feb 2019 22:06:42 +0100 Subject: identity: wip --- bug/bug.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'bug/bug.go') diff --git a/bug/bug.go b/bug/bug.go index 1717dd66..f84753fa 100644 --- a/bug/bug.go +++ b/bug/bug.go @@ -459,6 +459,7 @@ func (bug *Bug) Commit(repo repository.ClockedRepo) error { return err } + bug.staging.commitHash = hash bug.packs = append(bug.packs, bug.staging) bug.staging = OperationPack{} @@ -513,9 +514,8 @@ func (bug *Bug) Merge(repo repository.Repo, other Interface) (bool, error) { } ancestor, err := repo.FindCommonAncestor(bug.lastCommit, otherBug.lastCommit) - if err != nil { - return false, err + return false, errors.Wrap(err, "can't find common ancestor") } ancestorIndex := 0 -- cgit From d2483d83dd52365741f51eca106aa18c4e8d6420 Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Sat, 16 Feb 2019 17:32:30 +0100 Subject: identity: I can compile again !! --- bug/bug.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'bug/bug.go') diff --git a/bug/bug.go b/bug/bug.go index f84753fa..f1bd1114 100644 --- a/bug/bug.go +++ b/bug/bug.go @@ -321,6 +321,11 @@ func (bug *Bug) Validate() error { return fmt.Errorf("first operation should be a Create op") } + // The bug ID should be the hash of the first commit + if len(bug.packs) > 0 && string(bug.packs[0].commitHash) != bug.id { + return fmt.Errorf("bug id should be the first commit hash") + } + // Check that there is no more CreateOp op it := NewOperationIterator(bug) createCount := 0 @@ -349,7 +354,8 @@ func (bug *Bug) HasPendingOp() bool { // Commit write the staging area in Git and move the operations to the packs func (bug *Bug) Commit(repo repository.ClockedRepo) error { - if bug.staging.IsEmpty() { + + if !bug.NeedCommit() { return fmt.Errorf("can't commit a bug with no pending operation") } @@ -466,6 +472,17 @@ func (bug *Bug) Commit(repo repository.ClockedRepo) error { return nil } +func (bug *Bug) CommitAsNeeded(repo repository.ClockedRepo) error { + if !bug.NeedCommit() { + return nil + } + return bug.Commit(repo) +} + +func (bug *Bug) NeedCommit() bool { + return !bug.staging.IsEmpty() +} + func makeMediaTree(pack OperationPack) []repository.TreeEntry { var tree []repository.TreeEntry counter := 0 -- cgit