Skip to content

repos::hygiene runs from justfile CWD, not invocation directory #117

Description

@aguil

Summary

just repos::hygiene (and repos::hygiene-prune) fail when invoked from a jj workspace or git worktree checkout because the recipe runs bookmark-pr-hygiene.sh with the justfile directory as CWD (~), not the directory the operator invoked just from.

The recent GH_CONFIG_DIR profile export fix (PR #116 / 75158bb) correctly unblocks command gh auth for subprocesses, but does not address this cwd problem.

Reproduction

From a jj workspace (no colocated .git), e.g. ~/dev/projects/tmuxr/work:

cd ~/dev/projects/tmuxr/work
jj root   # succeeds
just repos::hygiene

Actual:

not inside a jj or git repository
error: recipe `hygiene` failed on line 16 with exit code 1

Expected: audit runs against the checkout in the current working directory.

Direct script invocation from the same directory works (modulo separate gh API flakiness):

cd ~/dev/projects/tmuxr/work
bash "$(chezmoi source-path)/scripts/bookmark-pr-hygiene.sh" audit

Root cause

repos.just resolves the script path from justfile_directory() but never cds into the invocation directory before executing:

hygiene *args:
  @set -euo pipefail; \
  _jd="{{ justfile_directory() }}"; \
  script="$_jd/scripts/bookmark-pr-hygiene.sh"; \
  ...
  bash "$script" audit {{ args }}

bookmark-pr-hygiene.sh auto-detects VCS mode via jj root / git rev-parse from current working directory. When just is invoked from a project-task workspace under ~/dev/projects/…, the recipe still runs in ~.

Proposed fix

Use just's invocation_directory() so hygiene runs where the operator stands:

hygiene *args:
  @set -euo pipefail; \
  _jd="{{ justfile_directory() }}"; \
  _inv="{{ invocation_directory() }}"; \
  script="$_jd/scripts/bookmark-pr-hygiene.sh"; \
  ...
  cd "$_inv" && bash "$script" audit {{ args }}

Apply the same pattern to hygiene-prune.

Secondary follow-up (optional)

When running the script directly from a jj workspace, back-to-back gh repo view + gh pr list calls sometimes fail with error connecting to api.github.com; a short delay or retry between calls succeeds. Worth considering retries or avoiding --search in bookmark-pr-hygiene.sh if this reproduces outside agent/sandbox environments.

Context

  • Hit while running bookmark/PR hygiene on aguil/work after merging PR fix shell, vim, and git startup compatibility #9 (fix/workd-sidebar-lag).
  • Docs say worktrees/jj workspaces are supported (docs/repo-maintenance.md); the just recipe cwd mismatch blocks the documented just repos::hygiene entry point from those checkouts.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions