git-lfs/commands/init_test.go

65 lines
1.5 KiB
Go
Raw Normal View History

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")
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")
2014-05-31 00:00:29 +00:00
cmd.Output = "Installing clean filter\n" +
"Installing smudge filter\n" +
"git media initialized"
2014-06-04 14:29:19 +00:00
prePushHookFile := filepath.Join(repo.Path, ".git", "hooks", "pre-push")
2014-05-31 00:00:29 +00:00
cmd.After(func() {
2014-06-04 14:29:19 +00:00
// assert media filter config
2014-05-31 00:00:29 +00:00
configs := GlobalGitConfig(t)
AssertIncludeString(t, "filter.media.clean=git media clean %f", configs)
AssertIncludeString(t, "filter.media.smudge=git media smudge %f", configs)
AssertIncludeString(t, "filter.media.required=true", configs)
2014-05-31 00:00:29 +00:00
found := 0
for _, line := range configs {
if strings.HasPrefix(line, "filter.media") {
found += 1
}
}
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")
cmd.Output = "Installing clean filter\n" +
"Installing smudge filter\n" +
"Hook already exists: " +
filepath.Join(repo.Path, ".git", "hooks", "pre-push") +
"\ngit media initialized"
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
})
repo.Test()
}