mirror of
https://github.com/chenasraf/gi_gen.git
synced 2026-05-17 17:48:01 +00:00
major bugfixes
This commit is contained in:
@@ -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{
|
||||
"/*",
|
||||
".",
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user