mislav/hub · error

Can't load git log %s..%s

Error message

Can't load git log %s..%s

What it means

Log() runs `git log --cherry a...b` to obtain the commit log between two SHAs and returns the raw output as a string. When the git log command fails, it wraps the failure as "Can't load git log <sha1>..<sha2>", meaning the range cannot be computed from the local object store.

Source

Thrown at git/git.go:236

	cmd.Stderr = nil
	cmd.WithArg("-c").WithArg("log.showSignature=false")
	cmd.WithArg("show").WithArg("-s").WithArg("--format=%s%n%+b").WithArg(sha)

	output, err := cmd.Output()
	return strings.TrimSpace(output), err
}

func Log(sha1, sha2 string) (string, error) {
	execCmd := cmd.New("git")
	execCmd.WithArg("-c").WithArg("log.showSignature=false").WithArg("log").WithArg("--no-color")
	execCmd.WithArg("--format=%h (%aN, %ar)%n%w(78,3,3)%s%n%+b")
	execCmd.WithArg("--cherry")
	shaRange := fmt.Sprintf("%s...%s", sha1, sha2)
	execCmd.WithArg(shaRange)

	outputs, err := execCmd.Output()
	if err != nil {
		return "", fmt.Errorf("Can't load git log %s..%s", sha1, sha2)
	}

	return outputs, nil
}

func Remotes() ([]string, error) {
	remoteCmd := gitCmd("remote", "-v")
	remoteCmd.Stderr = nil
	output, err := remoteCmd.Output()
	return outputLines(output), err
}

func Config(name string) (string, error) {
	return gitGetConfig(name)
}

func ConfigAll(name string) ([]string, error) {
	mode := "--get-all"

View on GitHub (pinned to 5c547ed804)

Solutions

  1. Fetch full history: git fetch --unshallow (or increase --depth)
  2. Verify both SHAs exist: git cat-file -e <sha>^{commit}
  3. Fetch the PR's base ref if working with fork branches
  4. Check for force-pushes that orphaned the referenced SHAs

Example fix

// before
out, err := git.Log(baseSha, headSha)
// after
if err := run("git", "fetch", "--unshallow"); err != nil {
    return err
}
out, err := git.Log(baseSha, headSha)
Defensive patterns

Strategy: retry

Validate before calling

for _, s := range []string{sha1, sha2} {
    if exec.Command("git", "cat-file", "-e", s+"^{commit}").Run() != nil {
        return fmt.Errorf("commit %s not present locally; fetch/unshallow first", s)
    }
}

Try / catch

out, err := git.Log(sha1, sha2)
if err != nil {
    _ = exec.Command("git", "fetch", "--unshallow").Run() // or fetch missing refs
    out, err = git.Log(sha1, sha2)
    if err != nil {
        return fmt.Errorf("git log %s...%s unavailable even after fetch", sha1, sha2)
    }
}

Prevention

When it happens

Trigger: Calling git.Log(sha1, sha2) (via pullRequest, TestGitLog) with unknown SHAs, SHAs from a shallow clone, or objects pruned by gc — rev-list/log then exits non-zero.

Common situations: Shallow CI checkouts (clone --depth 1) missing history between the SHAs; referencing SHAs from a force-pushed/rebased branch; fork PR base commits not fetched locally.

Related errors


AI-assisted analysis of mislav/hub@5c547ed804 (2026-09-01). Data as JSON: /api/errors/66a652aff231da01. Report an issue: GitHub.