major bugfixes

This commit is contained in:
Chen Asraf
2022-05-20 01:59:50 +03:00
parent e50550f0d0
commit bd11891a89
2 changed files with 22 additions and 24 deletions

View File

@@ -4,6 +4,7 @@ import (
"fmt"
"log"
"os"
"os/exec"
"path/filepath"
"strings"
@@ -20,8 +21,7 @@ func PrepareGitignores() ([]string, error) {
if GetNeedsUpdate() {
log.Println("Updating gitignore files...")
RunCmd("git", "pull", "origin", "master")
os.RemoveAll(filepath.Join(gitignoresDir, ".git"))
RunCmd("git", "-C", gitignoresDir, "pull", "origin", "master")
}
return GetGitignores(gitignoresDir)
@@ -29,14 +29,31 @@ func PrepareGitignores() ([]string, error) {
func GetCacheDir() string {
homeDir, _ := os.UserHomeDir()
gitignoresDir := filepath.Join(homeDir, ".github.gitignore")
return gitignoresDir
return filepath.Join(homeDir, ".github.gitignore")
}
func GetGitignores(sourceDir string) ([]string, error) {
return filepath.Glob(filepath.Join(sourceDir, "*.gitignore"))
}
func GetNeedsUpdate() bool {
gitignoresDir := GetCacheDir()
localBytes, localErr := exec.Command("git", "-C", gitignoresDir, "rev-parse", "@").Output()
baseBytes, baseErr := exec.Command("git", "-C", gitignoresDir, "merge-base", "@", "@{u}").Output()
if localErr != nil {
log.Fatal(localErr)
os.Exit(1)
}
if baseErr != nil {
log.Fatal(baseErr)
os.Exit(1)
}
localStr := string(localBytes)
baseStr := string(baseBytes)
return localStr == baseStr
}
var ignoreLines = []string{
"/*",
".",

View File

@@ -2,7 +2,6 @@ package internal
import (
"fmt"
"io/fs"
"log"
"os"
"os/exec"
@@ -26,23 +25,6 @@ func GlobExists(path string) bool {
return res != nil
}
func GetNeedsUpdate() bool {
localBytes, localErr := exec.Command("git", "rev-parse", "@").Output()
baseBytes, baseErr := exec.Command("git", "merge-base", "@", "@{u}").Output()
if localErr != nil {
log.Fatal(localErr)
os.Exit(1)
}
if baseErr != nil {
log.Fatal(baseErr)
os.Exit(1)
}
localStr := string(localBytes)
baseStr := string(baseBytes)
return localStr == baseStr
}
func RunCmd(cmd string, args ...string) (string, error) {
res, err := exec.Command(cmd, args...).Output()
return string(res), err
@@ -58,9 +40,8 @@ func WriteFile(path string, data string, overwrite bool) bool {
var err error
if overwrite {
// os.Create(path)
err = os.WriteFile(path, []byte(data), fs.ModeAppend)
err = os.WriteFile(path, []byte(data), 0644)
HandleErr(err)
} else {
f, err := os.OpenFile(path, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
HandleErr(err)