Skip to content

Commit 484466c

Browse files
Rename the GitHub CLI extension to gh gitsim
gh names an extension's command after its gh-<name> folder and script, so integrations/gh-sim becomes integrations/gh-gitsim, run as gh gitsim pr 42. The script's messages, refs, and temporary worktree, the README, and CONTRIBUTING use the new name. The README's star link now jumps to the top of the page, as git-dummy's does. Signed-off-by: Jacob Stopak <jacob@initialcommit.io>
1 parent 2000e45 commit 484466c

4 files changed

Lines changed: 70 additions & 70 deletions

File tree

‎CONTRIBUTING.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ $ git-sim merge dev
5454
- `src/git_sim/render/`: the static renderer, which draws the SVG, PNG, and JPG output and the interactive page
5555
- `src/git_sim/live.py`, `preflight.py`, `mcp_server.py`, `claude_hook.py`: live mode, pre-flight, the MCP server, and the agent hook
5656
- `vscode/`: the VS Code extension
57-
- `integrations/`: the GitHub CLI extension (`gh sim`) and the GitHub Action
57+
- `integrations/`: the GitHub CLI extension (`gh gitsim`) and the GitHub Action
5858
- `docs/img/`: the README's images
5959
- `scripts/`: the scripts that draw the README's graphs
6060

‎README.md‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -965,31 +965,31 @@ Pull requests from forks get a read-only token, which can't post comments, so se
965965
</details>
966966
967967
<details>
968-
<summary>GitHub CLI: gh sim</summary>
968+
<summary>GitHub CLI: gh gitsim</summary>
969969
970970
With the [GitHub CLI](https://github.com/cli/cli#installation) installed and logged in (`gh auth login`), install the extension from a clone of this repo:
971971

972972
```console
973973
$ git clone https://github.com/initialcommit-com/git-sim.git ~/git-sim
974-
$ cd ~/git-sim/integrations/gh-sim
974+
$ cd ~/git-sim/integrations/gh-gitsim
975975
$ gh extension install .
976976
```
977977

978978
Then, inside a clone of the pull request's repo:
979979

980980
```console
981-
$ gh sim pr 42 # what merging pull request #42 into its base would do
982-
$ gh sim pr 42 rebase # what rebasing it onto its base would do
981+
$ gh gitsim pr 42 # what merging pull request #42 into its base would do
982+
$ gh gitsim pr 42 rebase # what rebasing it onto its base would do
983983
```
984984

985-
`gh sim pr` simulates in a temporary worktree, so your checkout and branches are never touched. Any other `gh sim` command is the same as running git-sim. On Windows, `gh` runs the extension with the bash from Git for Windows.
985+
`gh gitsim pr` simulates in a temporary worktree, so your checkout and branches are never touched. Any other `gh gitsim` command is the same as running git-sim. On Windows, `gh` runs the extension with the bash from Git for Windows.
986986

987987
</details>
988988

989989
## Support git-sim
990990

991991
Git-Sim is Free and Open-Source Software (FOSS). Your support will help me work on it (and other Git projects) full time!
992-
- ⭐ [Star the repo](https://github.com/initialcommit-com/git-sim)
992+
- ⭐ [Star the repo](#top)
993993
- [Sponsor Git-Sim on GitHub](https://github.com/sponsors/initialcommit-com)
994994
- [Support Git-Sim via Patreon](https://patreon.com/user?u=92322459)
995995

‎integrations/gh-gitsim/gh-gitsim‎

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/usr/bin/env bash
2+
# gh gitsim: git-sim as a GitHub CLI extension.
3+
#
4+
# gh gitsim <git-sim arguments> the same as running git-sim
5+
# gh gitsim pr <number> [merge|rebase] what merging (or rebasing) a pull request
6+
# into its base would do, on this repository
7+
#
8+
# `gh gitsim pr` never touches your checkout: it fetches the pull request's head
9+
# and base into a temporary worktree, runs git-sim there, and removes it.
10+
#
11+
# Install: gh extension install . (from this folder, in a clone of git-sim)
12+
# Needs: git-sim on the PATH (pipx install git-sim) and gh logged in.
13+
set -euo pipefail
14+
15+
if ! command -v git-sim >/dev/null 2>&1; then
16+
echo "gh gitsim: git-sim is not installed. Run: pipx install git-sim" >&2
17+
exit 1
18+
fi
19+
20+
if [ "${1:-}" != "pr" ]; then
21+
exec git-sim "$@"
22+
fi
23+
24+
shift
25+
number="${1:-}"
26+
mode="${2:-merge}"
27+
if [ -z "$number" ]; then
28+
echo "usage: gh gitsim pr <number> [merge|rebase]" >&2
29+
exit 2
30+
fi
31+
case "$mode" in merge|rebase) ;; *) echo "gh gitsim pr: the mode is merge or rebase, not '$mode'" >&2; exit 2;; esac
32+
33+
read -r head base < <(gh pr view "$number" --json headRefName,baseRefName --jq '[.headRefName, .baseRefName] | @tsv')
34+
if [ -z "$head" ] || [ -z "$base" ]; then
35+
echo "gh gitsim pr: could not read pull request #$number" >&2
36+
exit 1
37+
fi
38+
39+
remote="$(git config --get "branch.$base.remote" 2>/dev/null || echo origin)"
40+
echo "gh gitsim: fetching #$number ($head -> $base) from $remote"
41+
git fetch -q "$remote" "refs/pull/$number/head:refs/gh-gitsim/pr-$number" "$base"
42+
43+
worktree="$(mktemp -d "${TMPDIR:-/tmp}/gh-gitsim.XXXXXX")"
44+
cleanup() {
45+
git worktree remove --force "$worktree" >/dev/null 2>&1 || true
46+
git branch -D "gh-gitsim/pr-$number" >/dev/null 2>&1 || true
47+
git update-ref -d "refs/gh-gitsim/pr-$number" >/dev/null 2>&1 || true
48+
}
49+
trap cleanup EXIT
50+
51+
# The base as the remote has it, checked out detached in the worktree, with
52+
# the pull request's head as a local branch git-sim can name.
53+
git worktree add -q --detach "$worktree" "$remote/$base"
54+
git branch -q -f "gh-gitsim/pr-$number" "refs/gh-gitsim/pr-$number"
55+
56+
cd "$worktree"
57+
if [ "$mode" = "rebase" ]; then
58+
# What the pull request's commits look like replayed onto the base.
59+
git switch -q -C "gh-gitsim/pr-$number" "refs/gh-gitsim/pr-$number"
60+
git-sim rebase "$remote/$base"
61+
else
62+
git-sim merge "gh-gitsim/pr-$number"
63+
fi

‎integrations/gh-sim/gh-sim‎

Lines changed: 0 additions & 63 deletions
This file was deleted.

0 commit comments

Comments
 (0)