Always show diffs for newly cloned packages

Newly cloned packages already start out at origin/master, so there is no
diff to show. Track if we cloned a package and if so make sure to show
the full diff
This commit is contained in:
morganamilo 2018-06-10 03:41:25 +01:00
parent 2b925aefa3
commit 00da26a3ce
No known key found for this signature in database
GPG key ID: 6FE9E7996B0B082E
2 changed files with 36 additions and 25 deletions

View file

@ -62,25 +62,25 @@ func gitHasDiff(path string, name string) (bool, error) {
return head != upstream, nil
}
func gitDownload(url string, path string, name string) error {
func gitDownload(url string, path string, name string) (bool, error) {
_, err := os.Stat(filepath.Join(path, name, ".git"))
if os.IsNotExist(err) {
err = passToGit(path, "clone", url, name)
if err != nil {
return fmt.Errorf("error cloning %s", name)
return false, fmt.Errorf("error cloning %s", name)
}
return nil
return true, nil
} else if err != nil {
return fmt.Errorf("error reading %s", filepath.Join(path, name, ".git"))
return false, fmt.Errorf("error reading %s", filepath.Join(path, name, ".git"))
}
err = passToGit(filepath.Join(path, name), "fetch")
if err != nil {
return fmt.Errorf("error fetching %s", name)
return false, fmt.Errorf("error fetching %s", name)
}
return nil
return false, nil
}
func gitMerge(url string, path string, name string) error {
@ -248,7 +248,7 @@ func getPkgbuildsfromAUR(pkgs []string, dir string) (bool, error) {
}
if shouldUseGit(filepath.Join(dir, pkg.PackageBase)) {
err = gitDownload(baseURL+"/"+pkg.PackageBase+".git", dir, pkg.PackageBase)
_, err = gitDownload(baseURL+"/"+pkg.PackageBase+".git", dir, pkg.PackageBase)
} else {
err = downloadAndUnpack(baseURL+aq[0].URLPath, dir)
}

View file

@ -156,14 +156,14 @@ func install(parser *arguments) error {
cleanBuilds(toClean)
toSkip := pkgBuildsToSkip(do.Aur, targets)
err = downloadPkgBuilds(do.Aur, do.Bases, toSkip)
cloned, err := downloadPkgBuilds(do.Aur, do.Bases, toSkip)
if err != nil {
return err
}
if len(toEdit) > 0 {
if config.ShowDiffs {
err = showPkgBuildDiffs(toEdit, do.Bases)
err = showPkgBuildDiffs(toEdit, do.Bases, cloned)
} else {
err = editPkgBuilds(toEdit, do.Bases)
}
@ -499,27 +499,33 @@ func cleanBuilds(pkgs []*rpc.Pkg) {
}
}
func showPkgBuildDiffs(pkgs []*rpc.Pkg, bases map[string][]*rpc.Pkg) error {
func showPkgBuildDiffs(pkgs []*rpc.Pkg, bases map[string][]*rpc.Pkg, cloned stringSet) error {
for _, pkg := range pkgs {
dir := filepath.Join(config.BuildDir, pkg.PackageBase)
if shouldUseGit(dir) {
hasDiff, err := gitHasDiff(config.BuildDir, pkg.PackageBase)
if err != nil {
return err
start := "HEAD"
if cloned.get(pkg.PackageBase) {
start = gitEmptyTree
} else {
hasDiff, err := gitHasDiff(config.BuildDir, pkg.PackageBase)
if err != nil {
return err
}
if !hasDiff {
fmt.Printf("%s %s: %s\n", bold(yellow(arrow)), cyan(formatPkgbase(pkg, bases)), bold("No changes -- skipping"))
continue
}
}
if !hasDiff {
fmt.Printf("%s %s: %s\n", bold(yellow(arrow)), cyan(formatPkgbase(pkg, bases)), bold("No changes -- skipping"))
continue
}
args := []string{"diff", "HEAD..HEAD@{upstream}", "--src-prefix", dir + "/", "--dst-prefix", dir + "/"}
args := []string{"diff", start + "..HEAD@{upstream}", "--src-prefix", dir + "/", "--dst-prefix", dir + "/"}
if useColor {
args = append(args, "--color=always")
} else {
args = append(args, "--color=never")
}
err = passToGit(dir, args...)
err := passToGit(dir, args...)
if err != nil {
return err
}
@ -630,7 +636,9 @@ func mergePkgBuilds(pkgs []*rpc.Pkg) error {
return nil
}
func downloadPkgBuilds(pkgs []*rpc.Pkg, bases map[string][]*rpc.Pkg, toSkip stringSet) error {
func downloadPkgBuilds(pkgs []*rpc.Pkg, bases map[string][]*rpc.Pkg, toSkip stringSet) (stringSet, error) {
cloned := make(stringSet)
for k, pkg := range pkgs {
if toSkip.get(pkg.PackageBase) {
str := bold(cyan("::") + " PKGBUILD up to date, Skipping (%d/%d): %s\n")
@ -643,19 +651,22 @@ func downloadPkgBuilds(pkgs []*rpc.Pkg, bases map[string][]*rpc.Pkg, toSkip stri
fmt.Printf(str, k+1, len(pkgs), cyan(formatPkgbase(pkg, bases)))
if shouldUseGit(filepath.Join(config.BuildDir, pkg.PackageBase)) {
err := gitDownload(baseURL+"/"+pkg.PackageBase+".git", config.BuildDir, pkg.PackageBase)
clone, err := gitDownload(baseURL+"/"+pkg.PackageBase+".git", config.BuildDir, pkg.PackageBase)
if err != nil {
return err
return nil, err
}
if clone {
cloned.set(pkg.PackageBase)
}
} else {
err := downloadAndUnpack(baseURL+pkg.URLPath, config.BuildDir)
if err != nil {
return err
return nil, err
}
}
}
return nil
return cloned, nil
}
func downloadPkgBuildsSources(pkgs []*rpc.Pkg, bases map[string][]*rpc.Pkg, incompatible stringSet) (err error) {