Jguer/yay · error

%s%w

Error message

%s%w

What it means

collectPkgbuildDiffs runs `git diff start..HEAD@{upstream}` inside each cloned AUR repo (excluding .SRCINFO) via cmdBuilder.Capture. When git exits non-zero, the captured stderr is prepended to the underlying error and accumulated into errs (%s%w). The overall diff flow then reports these per-package failures, so one bad clone can fail the whole review list.

Solutions

  1. Fix the clone: cd <builddir>/<pkg> && git remote set-url origin <AUR ssh/https URL> && git fetch origin, ensuring HEAD has an upstream (git branch -u origin/master)
  2. Re-clone the affected package: remove the package dir in BuildDir and rerun the diff/update so yay re-fetches it
  3. Check ownership/permissions (git safe.directory) if clones were created by root: chown -R $USER <builddir>/<pkg>
  4. Inspect stderr in the error message — it names the exact git failure; address that (corrupt .git → rm -rf and re-clone)

Example fix

// before
stdout, stderr, err := cmdBuilder.Capture(cmdBuilder.BuildGitCmd(ctx, dir, args...))
if err != nil { errs = append(errs, fmt.Errorf("%s%w", stderr, err)); continue }
// after
// pre-flight per repo so diff never fails on a broken clone:
cmd := exec.Command("git", "-C", dir, "rev-parse", "--abbrev-ref", "HEAD@{upstream}")
if err := cmd.Run(); err != nil {
    _ = os.RemoveAll(dir) // broken clone (no upstream/corrupt) — yay will re-clone
}
stdout, stderr, err := cmdBuilder.Capture(cmdBuilder.BuildGitCmd(ctx, dir, args...))
Defensive patterns

Strategy: validation

Validate before calling

// before diffing, ensure each clone has a valid upstream
for _, dir := range pkgDirs {
    cmd := exec.Command("git", "-C", dir, "rev-parse", "--abbrev-ref", "--verify", "HEAD@{upstream}")
    if err := cmd.Run(); err != nil {
        // missing/corrupt upstream: re-clone the package dir
        os.RemoveAll(dir)
    }
}

Try / catch

stdout, stderr, err := cmdBuilder.Capture(cmdBuilder.BuildGitCmd(ctx, dir, args...))
if err != nil {
    if isGitBroken(stderr) { // e.g. 'no upstream configured', 'not a git repository'
        os.RemoveAll(dir); return reCloneAndDiff(pkg)
    }
    errs = append(errs, fmt.Errorf("%s%w", stderr, err))
    continue
}

Prevention

When it happens

Trigger: The git diff command fails for a package's clone directory: repo has no upstream configured (or upstream ref missing), .git corrupted, the clone was made by an older layout, or git itself errors on revision 'HEAD@{upstream}'.

Common situations: Interrupted/cloned-then-pruned AUR checkouts where origin/upstream is unset; user manually moved the repo dir; git version/config (safe.directory) refusing to operate on a root-owned clone; partial clone after network failure.

Understand the failure class

Background: "git command failed": what it means when a tool shells out to git and git exits non-zero — this error's family across 21 libraries.

Related errors


AI-assisted analysis of Jguer/yay@328f4b4939 (2026-09-07). Data as JSON: /api/errors/18f7fd876206515c. Report an issue: GitHub.

Appendix: source

Thrown at pkg/menus/diff_menu.go:95

				continue
			}
		}

		args := []string{"--no-pager", "diff"}
		if text.UseColor {
			args = append(args, "--color=always")
		} else {
			args = append(args, "--color=never")
		}

		args = append(args,
			start+"..HEAD@{upstream}", "--src-prefix",
			dir+"/", "--dst-prefix", dir+"/", "--", ".", ":(exclude).SRCINFO",
		)

		stdout, stderr, err := cmdBuilder.Capture(cmdBuilder.BuildGitCmd(ctx, dir, args...))
		if err != nil {
			errs = append(errs, fmt.Errorf("%s%w", stderr, err))

			continue
		}

		if stdout == "" {
			continue
		}

		buf.WriteString(logger.SprintOperationInfo(gotext.Get("Showing diff for %s", text.Bold(pkg))))
		buf.WriteByte('\n')
		buf.WriteString(stdout)
		buf.WriteString("\n\n")
	}

	return buf.String(), errs
}

// Check whether or not a diff exists between the last reviewed diff and

View on GitHub (pinned to 328f4b4939)