forked from git-lfs/git-lfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.go
123 lines (108 loc) · 3.22 KB
/
setup.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package lfs
import (
"fmt"
"strings"
"github.com/git-lfs/git-lfs/tools"
)
var (
// prePushHook invokes `git lfs pre-push` at the pre-push phase.
prePushHook = NewStandardHook("pre-push", []string{
"#!/bin/sh\ngit lfs push --stdin $*",
"#!/bin/sh\ngit lfs push --stdin \"$@\"",
"#!/bin/sh\ngit lfs pre-push \"$@\"",
"#!/bin/sh\ncommand -v git-lfs >/dev/null 2>&1 || { echo >&2 \"\\nThis repository has been set up with Git LFS but Git LFS is not installed.\\n\"; exit 0; }\ngit lfs pre-push \"$@\"",
"#!/bin/sh\ncommand -v git-lfs >/dev/null 2>&1 || { echo >&2 \"\\nThis repository has been set up with Git LFS but Git LFS is not installed.\\n\"; exit 2; }\ngit lfs pre-push \"$@\"",
})
// postCheckoutHook invokes `git lfs post-checkout`
postCheckoutHook = NewStandardHook("post-checkout", []string{})
postCommitHook = NewStandardHook("post-commit", []string{})
postMergeHook = NewStandardHook("post-merge", []string{})
hooks = []*Hook{
prePushHook,
postCheckoutHook,
postCommitHook,
postMergeHook,
}
upgradeables = map[string][]string{
"clean": []string{"git-lfs clean %f"},
"smudge": []string{
"git-lfs smudge %f",
"git-lfs smudge --skip %f",
"git-lfs smudge -- %f",
"git-lfs smudge --skip -- %f",
},
"process": []string{
"git-lfs filter",
"git-lfs filter --skip",
"git-lfs filter-process",
"git-lfs filter-process --skip",
},
}
filters = &Attribute{
Section: "filter.lfs",
Properties: map[string]string{
"clean": "git-lfs clean -- %f",
"smudge": "git-lfs smudge -- %f",
"process": "git-lfs filter-process",
"required": "true",
},
Upgradeables: upgradeables,
}
passFilters = &Attribute{
Section: "filter.lfs",
Properties: map[string]string{
"clean": "git-lfs clean -- %f",
"smudge": "git-lfs smudge --skip -- %f",
"process": "git-lfs filter-process --skip",
"required": "true",
},
Upgradeables: upgradeables,
}
)
// Get user-readable manual install steps for hooks
func GetHookInstallSteps() string {
steps := make([]string, 0, len(hooks))
for _, h := range hooks {
steps = append(steps, fmt.Sprintf(
"Add the following to .git/hooks/%s:\n\n%s",
h.Type, tools.Indent(h.Contents)))
}
return strings.Join(steps, "\n\n")
}
// InstallHooks installs all hooks in the `hooks` var.
func InstallHooks(force bool) error {
for _, h := range hooks {
if err := h.Install(force); err != nil {
return err
}
}
return nil
}
// UninstallHooks removes all hooks in range of the `hooks` var.
func UninstallHooks() error {
for _, h := range hooks {
if err := h.Uninstall(); err != nil {
return err
}
}
return nil
}
// InstallFilters installs filters necessary for git-lfs to process normal git
// operations. Currently, that list includes:
// - smudge filter
// - clean filter
//
// An error will be returned if a filter is unable to be set, or if the required
// filters were not present.
func InstallFilters(opt InstallOptions, passThrough bool) error {
if passThrough {
return passFilters.Install(opt)
}
return filters.Install(opt)
}
// UninstallFilters proxies into the Uninstall method on the Filters type to
// remove all installed filters.
func UninstallFilters(opt InstallOptions) error {
filters.Uninstall(opt)
return nil
}