Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion seed_kb.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,20 @@
"show running services": "systemctl list-units --type=service --state=running",
"show recent system logs": "journalctl -n 50 --no-pager",
"show folder tree": "find . -maxdepth 2 -not -path '*/.*'",
"go back": "cd -"
"go back": "cd -",
"show git status": "git status",
"what did i change": "git diff",
"show staged changes": "git diff --staged",
"which branch am i on": "git branch --show-current",
"list local branches": "git branch",
"show recent commits": "git log --oneline -n 10",
"show the last commit": "git show HEAD",
"stage a file": "git add <file>",
"save my work": "git add -A && git commit -m <message>",
"create a git branch": "git switch -c <branch>",
"switch git branch": "git switch <branch>",
"stash my changes": "git stash push -m <message>",
"list saved stashes": "git stash list",
"restore my stashed work": "git stash pop",
"undo my last commit": "git reset --soft HEAD~1"
}
45 changes: 45 additions & 0 deletions tests/test_git_seed_phrases.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
"""Exercise new offline Git suggestions in an isolated repository."""

import json
import shlex
import subprocess
from pathlib import Path


SEED = json.loads((Path(__file__).parents[1] / "seed_kb.json").read_text())


def test_offline_git_suggestions_preserve_work(tmp_path):
def git(*args):
return subprocess.run(
["git", *args], cwd=tmp_path, check=True, capture_output=True, text=True
).stdout

def suggestion(phrase, **values):
command = SEED[phrase]
for name, value in values.items():
command = command.replace(f"<{name}>", shlex.quote(value))
assert "<" not in command
return subprocess.run(
command, shell=True, cwd=tmp_path, check=True, capture_output=True, text=True
).stdout

git("init", "-b", "main")
git("config", "user.name", "Fixture")
git("config", "user.email", "fixture@example.invalid")
(tmp_path / "notes.txt").write_text("first\n")
suggestion("save my work", message="Initial fixture")
assert suggestion("which branch am i on").strip() == "main"
suggestion("create a git branch", branch="feature")
assert suggestion("which branch am i on").strip() == "feature"
(tmp_path / "notes.txt").write_text("second\n")
assert "+second" in suggestion("what did i change")
suggestion("stage a file", file="notes.txt")
assert "+second" in suggestion("show staged changes")
suggestion("save my work", message="Second fixture")
assert "Second fixture" in suggestion("show recent commits")
assert "Second fixture" in suggestion("show the last commit")
suggestion("undo my last commit")
assert (tmp_path / "notes.txt").read_text() == "second\n"
assert "+second" in suggestion("show staged changes")
assert "Initial fixture" in git("log", "-1", "--format=%s")
Loading