DEV Community

Jonas Brømsø
Jonas Brømsø

Posted on

Release 0.12.0 of stevedore - minor feature enhancement

When initially I started working on stevedore the goal was to support .dockerignore, however since ignore files follow a common implementation pattern, stevedore can be used on other types of ignore files - if they follow the common format.

Recently I was cleaning up some repositories adding canonical ignore files, copied from: github/gitignore, which is a repository holding all of the ignore files offered from GitHub, these are well maintained and very useful.

Anyway in the process of doing so, I wanted to make sure how things looked, so I the question arose, can I see what is and version control and what is not, after I had updated the .gitignore file to the version from the GitHub repository.

The challenge here was actually from my #48in28 Exercism participation, where I am pretty familiar the standard layout for some repositories since I am familiar with tooling and language, working with new languages does not come with the same familiarity, so I found it made sense to use canonical definitions, hence the use of github/gitignore.

For example for Clojure

I copied the file from github/gitignore/Clojure.gitignore to local: .gitignore. I actually made a fork (perhaps not necessary) and a clone so I could work on the local filesystem

cp /Users/jonasbn/develop/github-forks/gitignore/Clojure.gitignore .gitignore
Enter fullscreen mode Exit fullscreen mode

After this I would run stevedore.

stevedore --ignorefile .gitignore --included --invertcolors
Enter fullscreen mode Exit fullscreen mode

And it would inform me of the result.

.clj-kondo
.exercism
.exercism/config.json
.exercism/metadata.json
.git
.gitignore
.stevedoreignore
HELP.md
README.md
deps.edn
project.clj
src
src/leap.clj
test
test/leap_test.clj
Enter fullscreen mode Exit fullscreen mode

And then the invert operation, to see what is excluded:

stevedore --ignorefile .gitignore --excluded --invertcolors
.cpcache
.cpcache/2823628308.basis
.cpcache/2823628308.cp
.cpcache/2823628308.main
.cpcache/2823628308.manifest
Enter fullscreen mode Exit fullscreen mode

And I am pretty satisfied with the result.

A minor note on the above examples. The repository has a .stevedoreignore file with the following contents:

.git/
Enter fullscreen mode Exit fullscreen mode

So the .git directory is excluded from the analysis.

Actually if I ask stevedore what is exluced using it's own ignore file:

stevedore --ignorefile .stevedoreignore --excluded --invertcolors
Enter fullscreen mode Exit fullscreen mode

I get the following:

.git
Enter fullscreen mode Exit fullscreen mode

As for the actual implementation. stevedore is written in Go and is one of the tools I am in the process of learning and stevedore became one of the exercises I assigned myself to get a proper example for learning Go.

stevedore uses github.com/sabhiram/go-gitignore.

It traverses the directory and makes string comparisons of the path against an instance of the above component.

If the path being inspected was a directory I would copy it and append a slash (/) and then check both.

var aliasedPath = path

if info.IsDir() {
    aliasedPath += "/"
}

if ignoreObject.MatchesPath(path) ||  ignoreObject.MatchesPath(aliasedPath) {
Enter fullscreen mode Exit fullscreen mode

And this worked.

Suggestions for better implementations, feedback, PRs etc. most welcome, since this was applied swiftly and it worked.

stevedore can be found on GitHub.

Top comments (0)