Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

link: add vcs type for local symlink fix #134 #308

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ Hound supports the following version control systems:
* Mercurial - use `"vcs" : "hg"` in the config
* SVN - use `"vcs" : "svn"` in the config
* Bazaar - use `"vcs" : "bzr"` in the config
* Local Symlink - use `"vcs": "link"` in the config

See [config-example.json](config-example.json) for examples of how to use each VCS.

Expand Down
8 changes: 7 additions & 1 deletion index/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ func containsString(haystack []string, needle string) bool {
return false
}

func indexAllFiles(opt *IndexOptions, dst, src string) error {
func indexAllFiles(opt *IndexOptions, dst, path string) error {
ix := index.Create(filepath.Join(dst, "tri"))
defer ix.Close()

Expand All @@ -350,6 +350,12 @@ func indexAllFiles(opt *IndexOptions, dst, src string) error {
}
defer fileHandle.Close()

src, err := filepath.EvalSymlinks(path)

if err != nil {
return err
}

if err := filepath.Walk(src, func(path string, info os.FileInfo, err error) error {
name := info.Name()
rel, err := filepath.Rel(src, path)
Expand Down
51 changes: 51 additions & 0 deletions vcs/link.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package vcs

import (
"log"
"os"
"strings"
)

func init() {
Register(newLinkVcs, "link")
}

type LinkVcsDriver struct{}

func newLinkVcs(b []byte) (Driver, error) {
return &LinkVcsDriver{}, nil
}

func (g *LinkVcsDriver) HeadRev(dir string) (string, error) {
realdir, err := os.Readlink(dir)
if err != nil {
log.Printf("Failed to read symlink %s", dir)
return "", err
}

stat, err := os.Stat(realdir)
if err != nil {
log.Printf("Failed to determine modification time of %s", realdir)
return "", err
}
log.Printf("modtime %s", stat.ModTime().String())
return stat.ModTime().String(), nil
}

func (g *LinkVcsDriver) Pull(dir string) (string, error) {
return g.HeadRev(dir)
}

func (g *LinkVcsDriver) Clone(dir, url string) (string, error) {
err := os.Symlink(strings.Replace(url, "file://", "", 1), dir)
if err != nil {
log.Printf("Failed to link %s, see output below\nContinuing...", url)
return "", err
}

return g.HeadRev(dir)
}

func (g *LinkVcsDriver) SpecialFiles() []string {
return []string{}
}