Skip to content

Commit

Permalink
Merge pull request #67 from klausenbusk/git-ignore
Browse files Browse the repository at this point in the history
Don't add versions ignored by git
  • Loading branch information
tc80 authored Jul 5, 2020
2 parents fe322f6 + 63bc683 commit 1928a3c
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 4 deletions.
5 changes: 5 additions & 0 deletions cmd/autoupdate/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ func doUpdateGit(ctx context.Context, pckg *packages.Package, gitpath string, ve
continue
}

if util.IsPathIgnoredByGit(ctx, util.GetCDNJSPath(), pckgpath) {
util.Debugf(ctx, "%s is ignored by git; aborting\n", pckgpath)
continue
}

util.Check(os.MkdirAll(pckgpath, os.ModePerm))

if len(filesToCopy) > 0 {
Expand Down
4 changes: 2 additions & 2 deletions cmd/autoupdate/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ func init() {
}

var (
basePath = util.GetEnv("BOT_BASE_PATH")
basePath = util.GetBotBasePath()
packagesPath = path.Join(basePath, "packages", "packages")
cdnjsPath = path.Join(basePath, "cdnjs")
cdnjsPath = util.GetCDNJSPath()

// initialize standard debug logger
logger = util.GetStandardLogger()
Expand Down
5 changes: 5 additions & 0 deletions cmd/autoupdate/npm.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ func doUpdateNpm(ctx context.Context, pckg *packages.Package, versions []npm.Ver
continue
}

if util.IsPathIgnoredByGit(ctx, util.GetCDNJSPath(), pckgpath) {
util.Debugf(ctx, "%s is ignored by git; aborting\n", pckgpath)
continue
}

util.Check(os.MkdirAll(pckgpath, os.ModePerm))

tarballDir := npm.DownloadTar(ctx, version.Tarball)
Expand Down
2 changes: 1 addition & 1 deletion compress/css.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var (
".css": true,
}

basePath = util.GetEnv("BOT_BASE_PATH")
basePath = util.GetBotBasePath()
cleanCSS = path.Join(basePath, "tools", "node_modules/clean-css-cli/bin/cleancss")
)

Expand Down
7 changes: 6 additions & 1 deletion util/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,14 @@ func GetBotBasePath() string {
return GetEnv("BOT_BASE_PATH")
}

// GetCDNJSPath gets the path to the cdnjs repo.
func GetCDNJSPath() string {
return path.Join(GetBotBasePath(), "cdnjs")
}

// GetCDNJSPackages gets the path to the cdnjs libraries.
func GetCDNJSPackages() string {
return path.Join(GetBotBasePath(), "cdnjs", "ajax", "libs")
return path.Join(GetCDNJSPath(), "ajax", "libs")
}

// HasHTTPProxy returns true if the http proxy environment
Expand Down
21 changes: 21 additions & 0 deletions util/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package util
import (
"context"
"os/exec"
"strings"
)

// UpdateGitRepo git pulls and rebases the repository.
Expand All @@ -14,3 +15,23 @@ func UpdateGitRepo(ctx context.Context, gitpath string) {
Debugf(ctx, "%s: run %s\n", gitpath, cmd)
CheckCmd(cmd.CombinedOutput())
}

// IsPathIgnoredByGit determines if a path is git ignored.
func IsPathIgnoredByGit(ctx context.Context, gitpath string, path string) bool {
// We don't know if "path" is a file or a directory, so let's try with and without /
return isPathIgnoredByGit(ctx, gitpath, path) || isPathIgnoredByGit(ctx, gitpath, path+"/")
}

func isPathIgnoredByGit(ctx context.Context, gitpath string, path string) bool {
// We need a relative path, so let's remove "gitpath"
path = strings.TrimPrefix(path, gitpath)
// In case "path" is a absolute path, we need to remove "/" afterwards to get a relative path
path = strings.TrimPrefix(path, "/")
args := []string{"check-ignore", "--quiet", "--no-index", path}

cmd := exec.Command("git", args...)
cmd.Dir = gitpath
Debugf(ctx, "%s: run %s\n", gitpath, cmd)

return cmd.Run() == nil
}

0 comments on commit 1928a3c

Please sign in to comment.