{"record":{"id":"a0fddad2779b1e40","repo":"plandex-ai/plandex","slug":"no-commits-found-before-time-s","errorCode":null,"errorMessage":"no commits found before time: %s","messagePattern":"no commits found before time: (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"app/server/db/git.go","lineNumber":258,"sourceCode":"\tcmd := exec.Command(\"git\", \"-C\", dir, \"log\", \"-n\", \"1\",\n\t\t\"--before=\"+gitFormattedTime,\n\t\t\"--pretty=%h@@|@@%B@>>>@\")\n\tlog.Printf(\"ADMIN - Executing command: %s\", cmd.String())\n\tres, err := cmd.CombinedOutput()\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"error getting latest commit before time for dir: %s, err: %v, output: %s\", dir, err, string(res))\n\t}\n\n\t// log.Printf(\"ADMIN - git log res: %s\", string(res))\n\n\toutput := strings.TrimSpace(string(res))\n\n\t// history := processGitHistoryOutput(strings.TrimSpace(string(res)))\n\n\t// log.Printf(\"ADMIN - History: %v\", history)\n\n\tif output == \"\" {\n\t\treturn \"\", fmt.Errorf(\"no commits found before time: %s\", before.Format(\"2006-01-02T15:04:05Z\"))\n\t}\n\n\tsha = strings.Split(output, \"@@|@@\")[0]\n\treturn sha, nil\n}\n\nfunc (repo *GitRepo) GitListBranches() ([]string, error) {\n\torgId := repo.orgId\n\tplanId := repo.planId\n\n\tdir := getPlanDir(orgId, planId)\n\n\tvar out bytes.Buffer\n\tcmd := exec.Command(\"git\", \"branch\", \"--format=%(refname:short)\")\n\tcmd.Dir = dir\n\tcmd.Stdout = &out\n\terr := cmd.Run()\n\tif err != nil {","sourceCodeStart":240,"sourceCodeEnd":276,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/db/git.go#L240-L276","documentation":"GetLatestCommitShaBeforeTime looks up the most recent commit whose timestamp is before a given time and parses the sha from git log output split on '@@|@@'. When the command output is empty — meaning git found no matching commits — the function returns this error with the formatted cutoff time. It signals 'nothing in history before this timestamp' rather than an exec failure.","triggerScenarios":"Calling GetLatestCommitShaBeforeTime with a `before` time earlier than the repository's first commit, or on a repo with no commits at all; also when the git log invocation silently produces no output (empty/corrupt repo).","commonSituations":"Caller passes a wrong timezone-formatted time (e.g. an unconverted local vs UTC time making `before` land before repo creation); brand-new plan repo with no history; caller miscomputes the cutoff for pagination/rewind.","solutions":["Verify the `before` timestamp is in the expected timezone/format (compare against `git log --date=iso` output for the repo).","Call only with times after the repo's earliest commit; clamp to the first commit's date if the caller needs 'the oldest available'.","Handle the empty-history case explicitly in the caller (treat as 'no prior version') instead of treating it as an exception where appropriate.","If the repo should have history, check you are pointing at the right repo dir and that HEAD exists (`git log -1`)."],"exampleFix":"// before\nsha, err := GetLatestCommitShaBeforeTime(repoDir, before)\n// after (guard in caller)\nfirstCommitTime := getFirstCommitTime(repoDir)\nif before.Before(firstCommitTime) {\n    return ErrNoCommitBeforeTime // handle as expected-empty, not failure\n}\nsha, err := GetLatestCommitShaBeforeTime(repoDir, before)","handlingStrategy":"fallback","validationCode":"func hasHistoryBefore(repoDir string, before time.Time) bool {\n    out, err := exec.Command(\"git\", \"-C\", repoDir, \"rev-list\", \"-n\", \"1\", \"--before=\"+before.Format(time.RFC3339), \"HEAD\").Output()\n    return err == nil && len(out) > 0\n}","typeGuard":null,"tryCatchPattern":"sha, err := GetLatestCommitShaBeforeTime(repoDir, before)\nif err != nil && strings.HasPrefix(err.Error(), \"no commits found before time\") {\n    // expected for very old cutoffs or empty repos: fall back to oldest commit or empty diff\n    sha, err = getOldestCommitSha(repoDir)\n    if err != nil {\n        return \"\", nil // no history at all\n    }\n}","preventionTips":["Validate the timezone/format of `before` timestamps before calling (UTC vs local confusion is the top cause).","Treat empty history as a normal, expected case in callers rather than an exception.","Check the repo actually has commits (`git log -1`) before time-based queries.","Clamp cutoffs to at least the repo's first commit time."],"tags":["git","history","empty-result"],"backgroundTag":"no-commits-found","analyzedSha":"e2d772072efadbe41d2946d97d79be55532dbab5","analyzedAt":"2026-09-05T20:56:53.631Z","contentChangedAt":"2026-09-05T20:56:53.631Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}