@@ -2,16 +2,11 @@ package lfs
2
2
3
3
import (
4
4
"fmt"
5
- "regexp"
6
5
"strings"
7
6
8
7
"github.com/github/git-lfs/git"
9
8
)
10
9
11
- var (
12
- valueRegexp = regexp.MustCompile("\\Agit[\\-\\s]media")
13
- )
14
-
15
10
// Attribute wraps the structure and some operations of Git's conception of an
16
11
// "attribute", as defined here: http://git-scm.com/docs/gitattributes.
17
12
type Attribute struct {
@@ -27,6 +22,8 @@ type Attribute struct {
27
22
// The Properties of an Attribute refer to all of the keys and values
28
23
// that define that Attribute.
29
24
Properties map[string]string
25
+ // Previous values of these attributes that can be automatically upgraded
26
+ Upgradeables map[string][]string
30
27
}
31
28
32
29
// InstallOptions serves as an argument to Install().
@@ -44,8 +41,13 @@ type InstallOptions struct {
44
41
// returned immediately, and the rest of the attributes will not be set.
45
42
func (a *Attribute) Install(opt InstallOptions) error {
46
43
for k, v := range a.Properties {
44
+ var upgradeables []string
45
+ if a.Upgradeables != nil {
46
+ // use pre-normalised key since caller will have set up the same
47
+ upgradeables = a.Upgradeables[k]
48
+ }
47
49
key := a.normalizeKey(k)
48
- if err := a.set(key, v, opt); err != nil {
50
+ if err := a.set(key, v, upgradeables, opt); err != nil {
49
51
return err
50
52
}
51
53
}
@@ -63,7 +65,7 @@ func (a *Attribute) normalizeKey(relative string) string {
63
65
// matching key already exists and the value is not equal to the desired value,
64
66
// an error will be thrown if force is set to false. If force is true, the value
65
67
// will be overridden.
66
- func (a *Attribute) set(key, value string, opt InstallOptions) error {
68
+ func (a *Attribute) set(key, value string, upgradeables []string, opt InstallOptions) error {
67
69
var currentValue string
68
70
if opt.Local {
69
71
currentValue = git.Config.FindLocal(key)
@@ -73,7 +75,7 @@ func (a *Attribute) set(key, value string, opt InstallOptions) error {
73
75
currentValue = git.Config.FindGlobal(key)
74
76
}
75
77
76
- if opt.Force || shouldReset(currentValue) {
78
+ if opt.Force || shouldReset(currentValue, upgradeables ) {
77
79
var err error
78
80
if opt.Local {
79
81
// ignore error for unset, git returns non-zero if missing
@@ -106,11 +108,17 @@ func (a *Attribute) Uninstall() {
106
108
107
109
// shouldReset determines whether or not a value is resettable given its current
108
110
// value on the system. If the value is empty (length = 0), then it will pass.
109
- // Otherwise, it will pass if the below regex matches.
110
- func shouldReset(value string) bool {
111
+ // It will also pass if it matches any upgradeable value
112
+ func shouldReset(value string, upgradeables []string ) bool {
111
113
if len(value) == 0 {
112
114
return true
113
115
}
114
116
115
- return valueRegexp.MatchString(value)
117
+ for _, u := range upgradeables {
118
+ if value == u {
119
+ return true
120
+ }
121
+ }
122
+
123
+ return false
116
124
}
0 commit comments