Skip to content
This repository was archived by the owner on Sep 9, 2020. It is now read-only.

Commit 7e27e80

Browse files
committed
Display all fields for a removed project in the lock diff
1 parent b237632 commit 7e27e80

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

testdata/txn_writer/expected_diff_output.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,14 @@ Add: [
99
}
1010
]
1111
Remove: [
12-
"github.com/stuff/placeholder"
12+
{
13+
"name": "github.com/stuff/placeholder",
14+
"version": "2.0.0",
15+
"revision": "6694017eeb4e20fd277b049bf29dba4895c97234",
16+
"packages": [
17+
"."
18+
]
19+
}
1320
]
1421
Modify: [
1522
{

txn_writer.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func (payload *SafeWriterPayload) HasVendor() bool {
5757
type LockDiff struct {
5858
HashDiff *StringDiff
5959
Add []LockedProjectDiff
60-
Remove []gps.ProjectRoot
60+
Remove []LockedProjectDiff
6161
Modify []LockedProjectDiff
6262
}
6363

@@ -111,12 +111,12 @@ func (diff *LockDiff) Format() (string, error) {
111111
// Fields are only populated when there is a difference, otherwise they are empty.
112112
// TODO(carolynvs) this should be moved to gps
113113
type LockedProjectDiff struct {
114-
Name gps.ProjectRoot `json:"name"`
114+
Name gps.ProjectRoot `json:"name"`
115115
Source *StringDiff `json:"repo,omitempty"`
116-
Version *StringDiff `json:"version,omitempty"`
117-
Branch *StringDiff `json:"branch,omitempty"`
118-
Revision *StringDiff `json:"revision,omitempty"`
119-
Packages []StringDiff `json:"packages,omitempty"`
116+
Version *StringDiff `json:"version,omitempty"`
117+
Branch *StringDiff `json:"branch,omitempty"`
118+
Revision *StringDiff `json:"revision,omitempty"`
119+
Packages []StringDiff `json:"packages,omitempty"`
120120
}
121121

122122
type StringDiff struct {
@@ -438,7 +438,7 @@ func diffLocks(l1 gps.Lock, l2 gps.Lock) *LockDiff {
438438
}
439439
i2next = i2 + 1 // Don't evaluate to this again
440440
case -1: // Found a new project
441-
add := buildAddProject(lp2)
441+
add := buildLockedProjectDiff(lp2)
442442
diff.Add = append(diff.Add, add)
443443
i2next = i2 + 1 // Don't evaluate to this again
444444
continue // Keep looking for a matching project
@@ -450,14 +450,15 @@ func diffLocks(l1 gps.Lock, l2 gps.Lock) *LockDiff {
450450
}
451451

452452
if !matched {
453-
diff.Remove = append(diff.Remove, pr1)
453+
remove := buildLockedProjectDiff(lp1)
454+
diff.Remove = append(diff.Remove, remove)
454455
}
455456
}
456457

457458
// Anything that still hasn't been evaluated are adds
458459
for i2 := i2next; i2 < len(p2); i2++ {
459460
lp2 := p2[i2]
460-
add := buildAddProject(lp2)
461+
add := buildLockedProjectDiff(lp2)
461462
diff.Add = append(diff.Add, add)
462463
}
463464

@@ -467,7 +468,7 @@ func diffLocks(l1 gps.Lock, l2 gps.Lock) *LockDiff {
467468
return &diff
468469
}
469470

470-
func buildAddProject(lp gps.LockedProject) LockedProjectDiff {
471+
func buildLockedProjectDiff(lp gps.LockedProject) LockedProjectDiff {
471472
r2, b2, v2 := getVersionInfo(lp.Version())
472473
var rev, version, branch *StringDiff
473474
if r2 != "" {

txn_writer_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,8 +415,8 @@ func TestSafeWriter_DiffLocks(t *testing.T) {
415415
t.Fatalf("Expected the lock diff to contain 1 removed project, got %d", len(diff.Remove))
416416
} else {
417417
remove := diff.Remove[0]
418-
if remove != "github.com/stuff/placeholder" {
419-
t.Fatalf("expected new project github.com/stuff/placeholder, got %s", remove)
418+
if remove.Name != "github.com/stuff/placeholder" {
419+
t.Fatalf("expected new project github.com/stuff/placeholder, got %s", remove.Name)
420420
}
421421
}
422422

0 commit comments

Comments
 (0)