Skip to content

Commit 9bf1a56

Browse files
authored
Merge pull request git-lfs#2404 from git-lfs/release-2.2-backport-2393
Backport git-lfs#2393 for v2.2.x: lfs: trace hook install, uninstall, upgrade
2 parents 28dec3f + f60cf68 commit 9bf1a56

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

lfs/hook.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/git-lfs/git-lfs/config"
1212
"github.com/git-lfs/git-lfs/errors"
1313
"github.com/git-lfs/git-lfs/git"
14+
"github.com/rubyist/tracerx"
1415
)
1516

1617
var (
@@ -38,7 +39,8 @@ func NewStandardHook(theType string, upgradeables []string) *Hook {
3839

3940
func (h *Hook) Exists() bool {
4041
_, err := os.Stat(h.Path())
41-
return err == nil
42+
43+
return !os.IsNotExist(err)
4244
}
4345

4446
// Path returns the desired (or actual, if installed) location where this hook
@@ -65,14 +67,18 @@ func (h *Hook) Dir() string {
6567
// directory. It returns and halts at any errors, and returns nil if the
6668
// operation was a success.
6769
func (h *Hook) Install(force bool) error {
70+
msg := fmt.Sprintf("Install hook: %s, force=%t, path=%s", h.Type, force, h.Path())
71+
6872
if err := os.MkdirAll(h.Dir(), 0755); err != nil {
6973
return err
7074
}
7175

7276
if h.Exists() && !force {
77+
tracerx.Printf(msg + ", upgrading...")
7378
return h.Upgrade()
7479
}
7580

81+
tracerx.Printf(msg)
7682
return h.write()
7783
}
7884

@@ -107,15 +113,19 @@ func (h *Hook) Uninstall() error {
107113
return errors.New("Not in a git repository")
108114
}
109115

116+
msg := fmt.Sprintf("Uninstall hook: %s, path=%s", h.Type, h.Path())
117+
110118
match, err := h.matchesCurrent()
111119
if err != nil {
112120
return err
113121
}
114122

115123
if !match {
124+
tracerx.Printf(msg + ", doesn't match...")
116125
return nil
117126
}
118127

128+
tracerx.Printf(msg)
119129
return os.RemoveAll(h.Path())
120130
}
121131

0 commit comments

Comments
 (0)