Skip to content

Commit c20692c

Browse files
committed
Status: add a 'TargetRef' field
1 parent 45207b2 commit c20692c

3 files changed

Lines changed: 15 additions & 4 deletions

File tree

pkg/vendir/fetch/git/status.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ func (d Sync) Status(target string) (*ctlstatus.Status, error) {
2020

2121
git := NewGit(d.opts, d.log, d.refFetcher)
2222

23-
status := ctlstatus.Status{}
23+
status := ctlstatus.Status{
24+
TargetRef: d.opts.Ref,
25+
}
2426

2527
out, _, err := git.cmdRunner.Run([]string{"rev-parse", "HEAD"}, []string{}, target)
2628
if err != nil {

pkg/vendir/fetch/hg/status.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ func (d Sync) Status(target string) (*ctlstatus.Status, error) {
4343
bookmarks := splitted[4]
4444

4545
status := ctlstatus.Status{
46+
TargetRef: d.opts.Ref,
4647
Ref: ctlstatus.CompleteReference{
4748
SHA: sha,
4849
},

pkg/vendir/status/status.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package status
55

66
import (
77
"fmt"
8+
"slices"
89
"strings"
910
)
1011

@@ -15,6 +16,7 @@ type CompleteReference struct {
1516
}
1617

1718
type Status struct {
19+
TargetRef string
1820
Ref CompleteReference
1921
UncommitedChanges []string
2022
LocalCsets []string
@@ -25,19 +27,25 @@ func (s Status) IsSafe() bool {
2527
}
2628

2729
func (s Status) String() string {
30+
messages := make([]string, 0, 3)
31+
2832
if s.IsSafe() {
29-
return "clean"
33+
messages = append(messages, "clean")
3034
}
3135

32-
messages := make([]string, 0, 2)
33-
3436
if len(s.UncommitedChanges) != 0 {
3537
messages = append(messages, fmt.Sprintf("%d uncommited changes", len(s.UncommitedChanges)))
3638
}
3739
if len(s.LocalCsets) != 0 {
3840
messages = append(messages, fmt.Sprintf("%d unpushed commits", len(s.LocalCsets)))
3941
}
4042

43+
if !strings.HasPrefix(s.Ref.SHA, s.TargetRef) &&
44+
!slices.Contains(s.Ref.Tags, s.TargetRef) &&
45+
!slices.Contains(s.Ref.Others, s.TargetRef) {
46+
messages = append(messages, "ref mismatch")
47+
}
48+
4149
return strings.Join(messages, ", ")
4250
}
4351

0 commit comments

Comments
 (0)