# Move ref mappings into validation

`353954d`→[main](/content/gh/entireio/git-sync/commits/main/index.html)·

## Sessions

676e38397f34View transcript

## Changes

3

- internal

- planner

- Mtypes.go+2/-4

- syncer

- Msyncer.go+1/-1

- validation

- Mvalidation.go+10/-6

```
6 unmodified lines

7
8
9
10
11
12
13
16 unmodified lines

30
31
32
32
33
34
35
33
34
35
36

6 unmodified lines

"strings"

"github.com/go-git/go-git/v6/plumbing"
	"github.com/soph/git-sync/internal/validation"

// RefKind distinguishes branch refs from tag refs.
16 unmodified lines

//)

// RefMapping is a user-specified source:target mapping.
type RefMapping struct {
	Source string
	Target string
}
type RefMapping = validation.RefMapping

// DesiredRef represents a source ref that should be mirrored to a target ref.
type DesiredRef struct {
```

Minternal/planner/types.go+2/-4

```
45 unmodified lines

46
47
48
49
49
50
51
52

45 unmodified lines

// RefMapping is a user-specified source:target ref mapping.
type RefMapping = planner.RefMapping
type RefMapping = validation.RefMapping

// Config holds all configuration for a sync operation.
type Config struct {
```

Minternal/syncer/syncer.go+1/-1

```
4 unmodified lines

5
6
7
8
9
8
9
10
2 unmodified lines

13
14
15
16
17
18
19
20
21
22
23
24
9 unmodified lines

34
35
36
33
37
38
39
36
40
41
42
43
44
41
45
46
43
47
48
49
50

4 unmodified lines

"strings"

"github.com/go-git/go-git/v6/plumbing"

"github.com/soph/git-sync/internal/planner"

)

const (
2 unmodified lines

ProtocolV2   = "v2"
)

// RefMapping is a user-specified source:target mapping.
type RefMapping struct {
	Source string
	Target string
}

// NormalizeProtocolMode validates the configured protocol mode and applies the
// default auto mode when the user did not specify one.
func NormalizeProtocolMode(mode string) (string, error) {
9 unmodified lines

// ParseMapping parses a CLI --map value into a planner mapping.
func ParseMapping(raw string) (planner.RefMapping, error) {
func ParseMapping(raw string) (RefMapping, error) {
	parts := strings.SplitN(raw, ":", 2)
	if len(parts) != 2 {
		return planner.RefMapping{}, fmt.Errorf("invalid --map %q, expected src:dst", raw)
		return RefMapping{}, fmt.Errorf("invalid --map %q, expected src:dst", raw)
	}
	source := strings.TrimSpace(parts[0])
	target := strings.TrimSpace(parts[1])
	if source == "" || target == "" {
		return planner.RefMapping{}, fmt.Errorf("invalid --map %q, expected src:dst", raw)
		return RefMapping{}, fmt.Errorf("invalid --map %q, expected src:dst", raw)
	}
	return planner.RefMapping{Source: source, Target: target}, nil
	return RefMapping{Source: source, Target: target}, nil
}

// ParseHaveRef normalizes a have-ref CLI value. Short names are treated as
```

Minternal/validation/validation.go+10/-6
