diff options
-rw-r--r-- | Gopkg.lock | 7 | ||||
-rw-r--r-- | Gopkg.toml | 2 | ||||
-rw-r--r-- | bug/bug.go | 6 | ||||
-rw-r--r-- | bug/bug_test.go | 3 | ||||
-rw-r--r-- | bug/op_set_metadata.go | 2 | ||||
-rw-r--r-- | bug/operation_iterator_test.go | 34 | ||||
-rw-r--r-- | commands/bridge_configure.go | 12 | ||||
-rw-r--r-- | misc/random_bugs/create_random_bugs.go | 31 | ||||
-rw-r--r-- | vendor/github.com/xanzy/go-gitlab/award_emojis.go | 2 | ||||
-rw-r--r-- | vendor/github.com/xanzy/go-gitlab/gitlab.go | 1 |
10 files changed, 64 insertions, 36 deletions
@@ -369,12 +369,12 @@ version = "v1.0.0" [[projects]] - digest = "1:a58711c8b908d88e28007ddebf529f40f4a9d34efe7ba729244d737f46a756ca" + digest = "1:3254b94c092d3b29b828cc4c457723ac875f4318bf801745b71ef437459a90e9" name = "github.com/xanzy/go-gitlab" packages = ["."] pruneopts = "UT" - revision = "457d4d018eaa1fad8e6c63502cebcd11ba60164e" - version = "v0.22.0" + revision = "d8e9de1d4b4477fe420696e10cd97491d518d90f" + version = "v0.22.1" [[projects]] branch = "master" @@ -498,6 +498,7 @@ "github.com/go-errors/errors", "github.com/gorilla/mux", "github.com/icrowley/fake", + "github.com/mattn/go-isatty", "github.com/phayes/freeport", "github.com/pkg/errors", "github.com/shurcooL/githubv4", @@ -74,7 +74,7 @@ [[constraint]] name = "github.com/xanzy/go-gitlab" - version = "0.22.0" + version = "0.22.1" [[constraint]] branch = "master" @@ -330,12 +330,18 @@ func (bug *Bug) Validate() error { } // Check that there is no more CreateOp op + // Check that there is no colliding operation's ID it := NewOperationIterator(bug) createCount := 0 + ids := make(map[entity.Id]struct{}) for it.Next() { if it.Value().base().OperationType == CreateOp { createCount++ } + if _, ok := ids[it.Value().Id()]; ok { + return fmt.Errorf("id collision: %s", it.Value().Id()) + } + ids[it.Value().Id()] = struct{}{} } if createCount != 1 { diff --git a/bug/bug_test.go b/bug/bug_test.go index 35e8a395..480d312e 100644 --- a/bug/bug_test.go +++ b/bug/bug_test.go @@ -73,8 +73,6 @@ func TestBugCommitLoad(t *testing.T) { bug1.Append(createOp) bug1.Append(setTitleOp) - bug1.Append(setTitleOp) - bug1.Append(addCommentOp) repo := repository.NewMockRepoForTest() @@ -90,7 +88,6 @@ func TestBugCommitLoad(t *testing.T) { // add more op - bug1.Append(setTitleOp) bug1.Append(addCommentOp) assert.True(t, bug1.NeedCommit()) diff --git a/bug/op_set_metadata.go b/bug/op_set_metadata.go index f99f836b..67f7e009 100644 --- a/bug/op_set_metadata.go +++ b/bug/op_set_metadata.go @@ -34,6 +34,8 @@ func (op *SetMetadataOperation) Apply(snapshot *Snapshot) { base.extraMetadata = make(map[string]string) } + // Apply the metadata in an immutable way: if a metadata already + // exist, it's not possible to override it. for key, val := range op.NewMetadata { if _, exist := base.extraMetadata[key]; !exist { base.extraMetadata[key] = val diff --git a/bug/operation_iterator_test.go b/bug/operation_iterator_test.go index b922bec1..fcc61d0f 100644 --- a/bug/operation_iterator_test.go +++ b/bug/operation_iterator_test.go @@ -1,12 +1,14 @@ package bug import ( - "github.com/MichaelMure/git-bug/identity" - "github.com/MichaelMure/git-bug/repository" - "github.com/stretchr/testify/assert" - + "fmt" "testing" "time" + + "github.com/stretchr/testify/assert" + + "github.com/MichaelMure/git-bug/identity" + "github.com/MichaelMure/git-bug/repository" ) func ExampleOperationIterator() { @@ -29,16 +31,20 @@ func TestOpIterator(t *testing.T) { unix := time.Now().Unix() createOp := NewCreateOp(rene, unix, "title", "message", nil) - setTitleOp := NewSetTitleOp(rene, unix, "title2", "title1") addCommentOp := NewAddCommentOp(rene, unix, "message2", nil) setStatusOp := NewSetStatusOp(rene, unix, ClosedStatus) labelChangeOp := NewLabelChangeOperation(rene, unix, []Label{"added"}, []Label{"removed"}) + var i int + genTitleOp := func() Operation { + i++ + return NewSetTitleOp(rene, unix, fmt.Sprintf("title%d", i), "") + } + bug1 := NewBug() // first pack bug1.Append(createOp) - bug1.Append(setTitleOp) bug1.Append(addCommentOp) bug1.Append(setStatusOp) bug1.Append(labelChangeOp) @@ -46,16 +52,16 @@ func TestOpIterator(t *testing.T) { assert.NoError(t, err) // second pack - bug1.Append(setTitleOp) - bug1.Append(setTitleOp) - bug1.Append(setTitleOp) + bug1.Append(genTitleOp()) + bug1.Append(genTitleOp()) + bug1.Append(genTitleOp()) err = bug1.Commit(mockRepo) assert.NoError(t, err) // staging - bug1.Append(setTitleOp) - bug1.Append(setTitleOp) - bug1.Append(setTitleOp) + bug1.Append(genTitleOp()) + bug1.Append(genTitleOp()) + bug1.Append(genTitleOp()) it := NewOperationIterator(bug1) @@ -65,7 +71,5 @@ func TestOpIterator(t *testing.T) { counter++ } - if counter != 11 { - t.Fatalf("Wrong count of value iterated (%d instead of 8)", counter) - } + assert.Equal(t, 10, counter) } diff --git a/commands/bridge_configure.go b/commands/bridge_configure.go index 12cc35e3..3562af17 100644 --- a/commands/bridge_configure.go +++ b/commands/bridge_configure.go @@ -94,8 +94,14 @@ func promptTarget() (string, error) { } func promptName(repo repository.RepoCommon) (string, error) { + defaultExist := core.BridgeExist(repo, defaultName) + for { - fmt.Printf("name [%s]: ", defaultName) + if defaultExist { + fmt.Printf("name: ") + } else { + fmt.Printf("name [%s]: ", defaultName) + } line, err := bufio.NewReader(os.Stdin).ReadString('\n') if err != nil { @@ -105,6 +111,10 @@ func promptName(repo repository.RepoCommon) (string, error) { line = strings.TrimRight(line, "\n") name := line + if defaultExist && name == "" { + continue + } + if name == "" { name = defaultName } diff --git a/misc/random_bugs/create_random_bugs.go b/misc/random_bugs/create_random_bugs.go index ea8833ee..b5c19e63 100644 --- a/misc/random_bugs/create_random_bugs.go +++ b/misc/random_bugs/create_random_bugs.go @@ -11,7 +11,7 @@ import ( "github.com/icrowley/fake" ) -type opsGenerator func(bug.Interface, identity.Interface) +type opsGenerator func(bug.Interface, identity.Interface, int64) type Options struct { BugNumber int @@ -61,6 +61,12 @@ func generateRandomBugsWithSeed(opts Options, seed int64) []*bug.Bug { rand.Seed(seed) fake.Seed(seed) + // At the moment git-bug has a risk of hash collision is simple + // operation (like open/close) are made with the same timestamp. + // As a temporary workaround, we use here an strictly increasing + // timestamp + timestamp := time.Now().Unix() + opsGenerators := []opsGenerator{ comment, comment, @@ -94,7 +100,8 @@ func generateRandomBugsWithSeed(opts Options, seed int64) []*bug.Bug { for j := 0; j < nOps; j++ { index := rand.Intn(len(opsGenerators)) - opsGenerators[index](b, randomPerson()) + opsGenerators[index](b, randomPerson(), timestamp) + timestamp++ } result[i] = b @@ -177,25 +184,25 @@ func paragraphs() string { return strings.Replace(p, "\t", "\n\n", -1) } -func comment(b bug.Interface, p identity.Interface) { - _, _ = bug.AddComment(b, p, time.Now().Unix(), paragraphs()) +func comment(b bug.Interface, p identity.Interface, timestamp int64) { + _, _ = bug.AddComment(b, p, timestamp, paragraphs()) } -func title(b bug.Interface, p identity.Interface) { - _, _ = bug.SetTitle(b, p, time.Now().Unix(), fake.Sentence()) +func title(b bug.Interface, p identity.Interface, timestamp int64) { + _, _ = bug.SetTitle(b, p, timestamp, fake.Sentence()) } -func open(b bug.Interface, p identity.Interface) { - _, _ = bug.Open(b, p, time.Now().Unix()) +func open(b bug.Interface, p identity.Interface, timestamp int64) { + _, _ = bug.Open(b, p, timestamp) } -func close(b bug.Interface, p identity.Interface) { - _, _ = bug.Close(b, p, time.Now().Unix()) +func close(b bug.Interface, p identity.Interface, timestamp int64) { + _, _ = bug.Close(b, p, timestamp) } var addedLabels []string -func labels(b bug.Interface, p identity.Interface) { +func labels(b bug.Interface, p identity.Interface, timestamp int64) { var removed []string nbRemoved := rand.Intn(3) for nbRemoved > 0 && len(addedLabels) > 0 { @@ -217,5 +224,5 @@ func labels(b bug.Interface, p identity.Interface) { // ignore error // if the randomisation produce no changes, no op // is added to the bug - _, _, _ = bug.ChangeLabels(b, p, time.Now().Unix(), added, removed) + _, _, _ = bug.ChangeLabels(b, p, timestamp, added, removed) } diff --git a/vendor/github.com/xanzy/go-gitlab/award_emojis.go b/vendor/github.com/xanzy/go-gitlab/award_emojis.go index 89452c8a..4c054f96 100644 --- a/vendor/github.com/xanzy/go-gitlab/award_emojis.go +++ b/vendor/github.com/xanzy/go-gitlab/award_emojis.go @@ -405,7 +405,7 @@ func (s *AwardEmojiService) createAwardEmojiOnNote(pid interface{}, resource str noteID, ) - req, err := s.client.NewRequest("POST", u, nil, options) + req, err := s.client.NewRequest("POST", u, opt, options) if err != nil { return nil, nil, err } diff --git a/vendor/github.com/xanzy/go-gitlab/gitlab.go b/vendor/github.com/xanzy/go-gitlab/gitlab.go index df044141..b8c951c5 100644 --- a/vendor/github.com/xanzy/go-gitlab/gitlab.go +++ b/vendor/github.com/xanzy/go-gitlab/gitlab.go @@ -14,6 +14,7 @@ // limitations under the License. // +// Package gitlab implements a GitLab API client. package gitlab import ( |