home / skills / dmmulroy / .dotfiles / vcs-detect

This skill detects whether jj or git is used in the current project before any VCS command to route to the correct tool.

npx playbooks add skill dmmulroy/.dotfiles --skill vcs-detect

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
1.9 KB
---
name: vcs-detect
description: Detect whether the current project uses jj (Jujutsu) or git for version control. Run this BEFORE any VCS command to use the correct tool.
---

# VCS Detection Skill

Detect the version control system in use before running any VCS commands.

## Why This Matters

- jj (Jujutsu) and git have different CLIs and workflows
- Running `git` commands in a jj repo (or vice versa) causes errors
- Some repos use jj with git colocated (both `.jj/` and `.git/` exist)

## Detection Logic

Both `jj root` and `git rev-parse --show-toplevel` walk up the filesystem to find repo root.

**Priority order:**

1. `jj root` succeeds → jj (handles colocated too)
2. `git rev-parse` succeeds → git
3. Both fail → no VCS

## Detection Command

```bash
if jj root &>/dev/null; then echo "jj"
elif git rev-parse --show-toplevel &>/dev/null; then echo "git"
else echo "none"
fi
```

## Command Mappings

| Operation | git | jj |
|-----------|-----|-----|
| Status | `git status` | `jj status` |
| Log | `git log` | `jj log` |
| Diff | `git diff` | `jj diff` |
| Commit | `git commit` | `jj commit` / `jj describe` |
| Branch list | `git branch` | `jj branch list` |
| New branch | `git checkout -b <name>` | `jj branch create <name>` |
| Push | `git push` | `jj git push` |
| Pull/Fetch | `git pull` / `git fetch` | `jj git fetch` |
| Rebase | `git rebase` | `jj rebase` |

## Usage

Before any VCS operation:

1. Run detection command
2. Use appropriate CLI based on result
3. If `none`, warn user directory is not version controlled

## Example Integration

```
User: Show me the git log
Agent: [Runs detection] -> Result: jj
Agent: [Runs `jj log` instead of `git log`]
```

## Colocated Repos

When both `.jj/` and `.git/` exist, the repo is "colocated":
- jj manages the working copy
- git is available for compatibility (GitHub, etc.)
- **Always prefer jj commands** in colocated repos

Overview

This skill detects whether the current project uses jj (Jujutsu) or git for version control and outputs which tool to use. It runs a lightweight probe before any VCS command so an agent or script can select the correct CLI and avoid errors. The skill favors jj when both systems are present (colocated repos).

How this skill works

It executes the native discovery commands that walk the filesystem to find the repository root. First it runs `jj root` and, if that succeeds, returns jj. If that fails it runs `git rev-parse --show-toplevel` and returns git on success. If both fail it reports none so callers know the directory is not version controlled.

When to use it

  • Before running any VCS command to avoid invoking the wrong tool
  • In automation or CI scripts that must support both jj and git repositories
  • When opening a repo that may be colocated with both .jj/ and .git/
  • In language agents that translate user VCS requests into concrete commands
  • During pre-flight checks for developer tooling or editor integrations

Best practices

  • Run the detection command at the start of any VCS-related workflow
  • Prefer jj when detection finds both jj and git present (colocated repos)
  • Cache the detected result for the session if the working directory is unchanged
  • Treat a `none` result as a signal to warn the user or initialize a repository
  • Keep the detection command simple and side-effect free (no writes)

Example use cases

  • An assistant receives “Show me the log” and runs detection to choose `jj log` or `git log`
  • A CI step adapts its fetch/checkout commands depending on the repo's VCS
  • An editor plugin decides which status and branch commands to run for the open project
  • A wrapper script exposes unified commands and delegates to the correct VCS
  • A migration tool verifies target repositories and avoids running incompatible commands

FAQ

What exact command does the skill run?

It runs `jj root` and falls back to `git rev-parse --show-toplevel`; if neither succeeds it reports none.

Why prefer jj when both .jj/ and .git/ exist?

In colocated repos jj manages the working copy and should be the command used for repository operations; git may be present for compatibility only.