Show diffs before merging

This is what 5775e3..43d2a6 has been leading up to. Git fetch will be
called on all pkgbuilds, then the user is offered a chance to view the
diffs. If they choose to continue, merging happens. This allows users to
abort the install after viewing diffs and still be able to see thoes
diffs again if they try to install later on.

This also makes the git stuff a little more modular which should help in
organzing diff showing + pkgbuild editing.
This commit is contained in:
morganamilo 2018-06-10 01:57:17 +01:00
parent 43d2a6601a
commit 4f8b43cd60
No known key found for this signature in database
GPG Key ID: 6FE9E7996B0B082E
2 changed files with 26 additions and 43 deletions

View File

@ -44,13 +44,22 @@ func downloadFile(path string, url string) (err error) {
return err
}
func gitGetHash(path string, name string) (string, error) {
func gitHasDiff(path string, name string) (bool, error) {
stdout, stderr, err := passToGitCapture(filepath.Join(path, name), "rev-parse", "HEAD")
if err != nil {
return "", fmt.Errorf("%s%s", stderr, err)
return false, fmt.Errorf("%s%s", stderr, err)
}
return strings.TrimSpace(stdout), nil
head := strings.TrimSpace(stdout)
stdout, stderr, err = passToGitCapture(filepath.Join(path, name), "rev-parse", "HEAD@{upstream}")
if err != nil {
return false, fmt.Errorf("%s%s", stderr, err)
}
upstream := strings.TrimSpace(stdout)
return head != upstream, nil
}
func gitDownload(url string, path string, name string) error {

View File

@ -155,27 +155,17 @@ func install(parser *arguments) error {
cleanBuilds(toClean)
oldHashes, err := getHashes(do.Aur)
if err != nil {
return err
}
toSkip := pkgBuildsToSkip(do.Aur, targets)
err = downloadPkgBuilds(do.Aur, do.Bases, toSkip)
if err != nil {
return err
}
err = mergePkgBuilds(do.Aur)
if err != nil {
return err
}
if len(toEdit) > 0 {
if config.ShowDiffs {
err = showPkgBuildDiffs(toEdit, do.Bases, oldHashes)
err = showPkgBuildDiffs(toEdit, do.Bases)
} else {
err = editPkgBuilds(toEdit, do.Bases, oldHashes)
err = editPkgBuilds(toEdit, do.Bases)
}
if err != nil {
return err
@ -189,6 +179,12 @@ func install(parser *arguments) error {
config.NoConfirm = oldValue
}
err = mergePkgBuilds(do.Aur)
if err != nil {
return err
}
//initial srcinfo parse before pkgver() bump
err = parseSRCINFOFiles(do.Aur, srcinfosStale, do.Bases)
if err != nil {
@ -504,26 +500,21 @@ func cleanBuilds(pkgs []*rpc.Pkg) {
}
}
func showPkgBuildDiffs(pkgs []*rpc.Pkg, bases map[string][]*rpc.Pkg, hashes map[string]string) error {
func showPkgBuildDiffs(pkgs []*rpc.Pkg, bases map[string][]*rpc.Pkg) error {
for _, pkg := range pkgs {
dir := filepath.Join(config.BuildDir, pkg.PackageBase)
if shouldUseGit(dir) {
hash, _ := hashes[pkg.PackageBase]
if hash == "" {
hash = gitEmptyTree
}
head, err := gitGetHash(config.BuildDir, pkg.PackageBase)
hasDiff, err := gitHasDiff(config.BuildDir, pkg.PackageBase)
if err != nil {
return err
}
if head == hash {
if !hasDiff {
fmt.Printf("%s %s: %s\n", bold(yellow(arrow)), cyan(formatPkgbase(pkg, bases)), bold("No changes -- skipping"))
continue
}
args := []string{"diff", hash + "..HEAD", "--src-prefix", dir + "/", "--dst-prefix", dir + "/"}
args := []string{"diff", "HEAD..HEAD@{upstream}", "--src-prefix", dir + "/", "--dst-prefix", dir + "/"}
if useColor {
args = append(args, "--color=always")
} else {
@ -548,7 +539,7 @@ func showPkgBuildDiffs(pkgs []*rpc.Pkg, bases map[string][]*rpc.Pkg, hashes map[
return nil
}
func editPkgBuilds(pkgs []*rpc.Pkg, bases map[string][]*rpc.Pkg, hashes map[string]string) error {
func editPkgBuilds(pkgs []*rpc.Pkg, bases map[string][]*rpc.Pkg) error {
pkgbuilds := make([]string, 0, len(pkgs))
for _, pkg := range pkgs {
dir := filepath.Join(config.BuildDir, pkg.PackageBase)
@ -627,23 +618,6 @@ func pkgBuildsToSkip(pkgs []*rpc.Pkg, targets stringSet) stringSet {
return toSkip
}
func getHashes(pkgs []*rpc.Pkg) (map[string]string, error) {
hashes := make(map[string]string)
for _, pkg := range pkgs {
if shouldUseGit(filepath.Join(config.BuildDir, pkg.PackageBase)) {
hash, err := gitGetHash(config.BuildDir, pkg.PackageBase)
if err != nil {
return hashes, err
}
hashes[pkg.PackageBase] = hash
}
}
return hashes, nil
}
func mergePkgBuilds(pkgs []*rpc.Pkg) error {
for _, pkg := range pkgs {
if shouldUseGit(filepath.Join(config.BuildDir, pkg.PackageBase)) {