2014-06-04 17:40:09 +00:00
|
|
|
package commands
|
2014-05-31 00:00:29 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/bmizerany/assert"
|
2014-06-04 14:29:19 +00:00
|
|
|
"io/ioutil"
|
2014-05-31 00:00:29 +00:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2014-06-04 17:40:09 +00:00
|
|
|
func TestInit(t *testing.T) {
|
2014-05-31 00:00:29 +00:00
|
|
|
repo := NewRepository(t, "empty")
|
2014-06-04 18:57:20 +00:00
|
|
|
defer repo.Test()
|
|
|
|
|
2014-06-04 17:44:07 +00:00
|
|
|
repo.AddPath(repo.Path, ".git")
|
|
|
|
repo.AddPath(repo.Path, "subdir")
|
2014-05-31 00:00:29 +00:00
|
|
|
|
2014-06-04 17:40:09 +00:00
|
|
|
cmd := repo.Command("init")
|
2015-03-19 19:30:55 +00:00
|
|
|
cmd.Output = "git lfs initialized"
|
2014-05-31 00:00:29 +00:00
|
|
|
|
2014-06-04 14:29:19 +00:00
|
|
|
prePushHookFile := filepath.Join(repo.Path, ".git", "hooks", "pre-push")
|
|
|
|
|
2014-08-06 20:41:43 +00:00
|
|
|
cmd.Before(func() {
|
|
|
|
err := os.RemoveAll(filepath.Join(repo.Path, ".git", "hooks"))
|
|
|
|
assert.Equal(t, nil, err)
|
|
|
|
})
|
|
|
|
|
2014-05-31 00:00:29 +00:00
|
|
|
cmd.After(func() {
|
2015-03-19 19:30:55 +00:00
|
|
|
// assert filter config
|
2014-05-31 00:00:29 +00:00
|
|
|
configs := GlobalGitConfig(t)
|
2015-03-19 19:30:55 +00:00
|
|
|
AssertIncludeString(t, "filter.lfs.clean=git lfs clean %f", configs)
|
|
|
|
AssertIncludeString(t, "filter.lfs.smudge=git lfs smudge %f", configs)
|
|
|
|
AssertIncludeString(t, "filter.lfs.required=true", configs)
|
2014-05-31 00:00:29 +00:00
|
|
|
found := 0
|
|
|
|
for _, line := range configs {
|
2015-03-19 19:30:55 +00:00
|
|
|
if strings.HasPrefix(line, "filter.lfs") {
|
2014-05-31 00:00:29 +00:00
|
|
|
found += 1
|
|
|
|
}
|
|
|
|
}
|
2014-06-02 13:45:36 +00:00
|
|
|
assert.Equal(t, 3, found)
|
2014-06-04 14:29:19 +00:00
|
|
|
|
|
|
|
// assert hooks
|
|
|
|
stat, err := os.Stat(prePushHookFile)
|
|
|
|
assert.Equal(t, nil, err)
|
|
|
|
assert.Equal(t, false, stat.IsDir())
|
|
|
|
})
|
|
|
|
|
|
|
|
cmd = repo.Command("init")
|
2015-04-24 17:33:22 +00:00
|
|
|
cmd.Output = "Hook already exists: pre-push\n\necho 'yo'\n\ngit lfs initialized"
|
2014-06-04 14:29:19 +00:00
|
|
|
|
|
|
|
customHook := []byte("echo 'yo'")
|
|
|
|
cmd.Before(func() {
|
|
|
|
err := ioutil.WriteFile(prePushHookFile, customHook, 0755)
|
|
|
|
assert.Equal(t, nil, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
cmd.After(func() {
|
|
|
|
by, err := ioutil.ReadFile(prePushHookFile)
|
|
|
|
assert.Equal(t, nil, err)
|
|
|
|
assert.Equal(t, string(customHook), string(by))
|
2014-05-31 00:00:29 +00:00
|
|
|
})
|
|
|
|
}
|