Skip to content

Commit 1b57d28

Browse files
committed
bug fixes and improvements
1 parent 8efa358 commit 1b57d28

21 files changed

Lines changed: 1085 additions & 229 deletions

‎.githooks/post-commit‎

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

‎.githooks/pre-commit‎

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#!/bin/sh
2+
#
3+
# pre-commit hook: bumps the version in Cargo.toml as part of every commit.
4+
# The bump is staged before git writes the commit, so nothing is amended
5+
# afterwards: the hash git prints is final and a signed commit is signed once.
6+
#
7+
# Versions are X.Y.Z. Each commit bumps Z.
8+
#
9+
# GITST_BUMP=minor git commit ... bumps Y and resets Z.
10+
# GITST_BUMP=major git commit ... bumps X and resets Y and Z.
11+
# GITST_BUMP=none git commit ... keeps the version.
12+
#
13+
# Left alone: amends (they keep the version of the commit they replace), a
14+
# commit whose staged Cargo.toml already changes the version (set by hand),
15+
# `git commit <paths>`, and commits made by merge, rebase, cherry-pick and
16+
# revert. `--no-verify` skips this hook, and with it the bump.
17+
#
18+
# Only the staged Cargo.toml and Cargo.lock are bumped, plus the same line in
19+
# the working tree, so unstaged edits to those files stay out of the commit.
20+
#
21+
# Enable once per clone: git config core.hooksPath .githooks
22+
23+
[ "$GITST_BUMP" = none ] && exit 0
24+
25+
GIT_DIR="$(git rev-parse --git-dir)"
26+
27+
if [ -d "$GIT_DIR/rebase-merge" ] || [ -d "$GIT_DIR/rebase-apply" ] \
28+
|| [ -f "$GIT_DIR/CHERRY_PICK_HEAD" ] || [ -f "$GIT_DIR/REVERT_HEAD" ] \
29+
|| [ -f "$GIT_DIR/MERGE_HEAD" ]; then
30+
exit 0
31+
fi
32+
# `git commit <paths>` commits from a temporary index, and a bump staged
33+
# there would be missing from the real one afterwards.
34+
case "$GIT_INDEX_FILE" in
35+
*next-index*) exit 0 ;;
36+
esac
37+
# A root commit keeps the version it was made with.
38+
git rev-parse -q --verify HEAD >/dev/null || exit 0
39+
40+
# An amend shows on git's command line (aliases are expanded by then).
41+
# Without ps, fall back on the author date git passes to hooks, which an
42+
# amend keeps from HEAD.
43+
ARGS="$(ps -o args= -p "$PPID" 2>/dev/null)"
44+
if [ -n "$ARGS" ]; then
45+
case " $ARGS " in
46+
*" --amend "*) exit 0 ;;
47+
esac
48+
elif [ "$GIT_AUTHOR_DATE" = "@$(git log -1 --format=%ad --date=raw)" ]; then
49+
exit 0
50+
fi
51+
52+
cd "$(git rev-parse --show-toplevel)" || exit 0
53+
54+
version_of() {
55+
sed -n 's/^version = "\([0-9]*\.[0-9]*\.[0-9]*\)".*/\1/p' | head -n 1
56+
}
57+
58+
HEAD_VERSION="$(git show HEAD:Cargo.toml 2>/dev/null | version_of)"
59+
STAGED="$(git show :Cargo.toml 2>/dev/null | version_of)"
60+
[ -n "$HEAD_VERSION" ] && [ -n "$STAGED" ] || exit 0
61+
62+
NEW="$STAGED"
63+
if [ "$STAGED" = "$HEAD_VERSION" ]; then
64+
MAJOR="$(echo "$STAGED" | cut -d. -f1)"
65+
MINOR="$(echo "$STAGED" | cut -d. -f2)"
66+
PATCH="$(echo "$STAGED" | cut -d. -f3)"
67+
case "$GITST_BUMP" in
68+
major) MAJOR=$((MAJOR + 1)) MINOR=0 PATCH=0 ;;
69+
minor) MINOR=$((MINOR + 1)) PATCH=0 ;;
70+
*) PATCH=$((PATCH + 1)) ;;
71+
esac
72+
NEW="$MAJOR.$MINOR.$PATCH"
73+
fi
74+
75+
# Only the first `version =` line: the [package] one.
76+
bump_toml() { perl -pe "\$d ||= s/^version = \"[0-9.]+\"/version = \"$NEW\"/"; }
77+
# Cargo.lock too, also after a hand edit, so release builds can use --locked.
78+
bump_lock() { perl -0pe "s/(\[\[package\]\]\nname = \"gitst\"\nversion = \")[0-9.]+/\${1}$NEW/"; }
79+
80+
# Rewrites the staged copy of $1 through $2, and the working copy the same way.
81+
bump() {
82+
git ls-files --error-unmatch -- "$1" >/dev/null 2>&1 || return 0
83+
mode="$(git ls-files -s -- "$1" | cut -d' ' -f1)"
84+
blob="$(git show ":$1" | $2 | git hash-object -w --stdin)" || return 0
85+
git update-index --cacheinfo "$mode,$blob,$1" || return 0
86+
$2 <"$1" >"$1.bump" && cat "$1.bump" >"$1"
87+
rm -f "$1.bump"
88+
}
89+
bump Cargo.toml bump_toml
90+
bump Cargo.lock bump_lock
91+
92+
[ "$NEW" = "$HEAD_VERSION" ] || echo "gitst $HEAD_VERSION -> $NEW"
93+
exit 0

‎.github/workflows/ci.yml‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: CI
2+
3+
# Checks formatting and lints, and runs the tests, on every push and pull
4+
# request, on each platform gitst is released for.
5+
6+
on:
7+
push:
8+
branches: ["**"]
9+
pull_request:
10+
11+
env:
12+
CARGO_TERM_COLOR: always
13+
14+
permissions:
15+
contents: read
16+
17+
jobs:
18+
test:
19+
name: Test (${{ matrix.os }})
20+
runs-on: ${{ matrix.os }}
21+
strategy:
22+
fail-fast: false
23+
matrix:
24+
os: [ubuntu-latest, macos-latest, windows-latest]
25+
26+
steps:
27+
- uses: actions/checkout@v7
28+
29+
- name: Add rustfmt and clippy
30+
run: rustup component add rustfmt clippy
31+
32+
- name: Format
33+
if: runner.os == 'Linux'
34+
run: cargo fmt --check
35+
36+
- name: Clippy
37+
run: cargo clippy --locked --all-targets -- -D warnings
38+
39+
- name: Test
40+
run: cargo test --locked

‎.github/workflows/release.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ jobs:
5555
run: rustup target add ${{ matrix.target }}
5656

5757
- name: Build (release)
58-
# --locked works because the post-commit hook keeps Cargo.lock's
59-
# gitst version in step with Cargo.toml.
58+
# --locked works because the pre-commit hook (.githooks) keeps
59+
# Cargo.lock's gitst version in step with Cargo.toml.
6060
run: cargo build --release --locked --target ${{ matrix.target }}
6161

6262
- name: Package

‎Cargo.lock‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "gitst"
3-
version = "0.1.4"
3+
version = "0.1.5"
44
edition = "2024"
55
description = "Live, glanceable git status TUI for small terminal panes"
66
license = "MIT"
@@ -15,7 +15,7 @@ dirs = "6"
1515
ignore = "0.4"
1616
notify = "8"
1717
ratatui = "0.30"
18-
serde = { version = "1", features = ["derive"] }
18+
serde = "1"
1919
terminal-colorsaurus = "1.0"
2020
toml = "1"
2121
unicode-segmentation = "1"
@@ -31,6 +31,7 @@ windows-sys = { version = "0.61", features = [
3131
"Win32_Security",
3232
"Win32_System_JobObjects",
3333
"Win32_System_LibraryLoader",
34+
"Win32_System_SystemInformation",
3435
"Win32_System_Threading",
3536
] }
3637

‎README.md‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,10 @@ gitst --version
9292

9393
## Config
9494

95-
Optional, at `~/.config/gitst/config.toml`. All keys are optional; these are the
96-
defaults:
95+
Optional. gitst reads the first of these that exists:
96+
`$XDG_CONFIG_HOME/gitst/config.toml` (when that is set),
97+
`%APPDATA%\gitst\config.toml` (Windows) and `~/.config/gitst/config.toml`.
98+
All keys are optional; these are the defaults:
9799

98100
```toml
99101
fetch_interval = "5m" # "0" turns the timer off; ↻ and f still work
@@ -106,7 +108,8 @@ numstat_max_files = 500 # skip +/− counts above this many changes
106108
```
107109

108110
Section names for `collapsed` are `changes`, `activity`, `commits`, `branches`
109-
and `stashes`. An invalid file is reported in the UI and the defaults are used.
111+
and `stashes`. Unknown keys and invalid values are named in the UI and keep their
112+
defaults; the rest of the file still applies.
110113

111114
## Notes
112115

0 commit comments

Comments
 (0)