aboutsummaryrefslogtreecommitdiffstats
path: root/desktop/modules/git/gitcfg
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-10-16 11:22:41 +0200
committerDanilo M. <danix@danix.xyz>2026-10-16 11:22:41 +0200
commite97d5dea1d2b36ee9882de8699b382cf4fef64ae (patch)
treee54a0d12d60049185f90792aa1077ca4f3622e7c /desktop/modules/git/gitcfg
parent02f7797aaf6ab9e5c4a2a89ab0efb33b43349e90 (diff)
downloadquickshell-e97d5dea1d2b36ee9882de8699b382cf4fef64ae.tar.gz
quickshell-e97d5dea1d2b36ee9882de8699b382cf4fef64ae.zip
fix(git): refuse duplicate values, show list errors, Escape on Add
Review findings. With a key holding the same value twice, --fixed-value --replace-all rewrote both and merged two rows into one, and --unset failed on both; gitcfg now counts the matches and refuses anything but exactly one, pointing at the editor. A file git cannot parse made list print nothing, which the page drew as an empty config; list now prints git's error as an error= line and the page shows it. Escape in the Add fields clears the typed text before it leaves the page, as a row's edit is undone first. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'desktop/modules/git/gitcfg')
-rwxr-xr-xdesktop/modules/git/gitcfg26
1 files changed, 19 insertions, 7 deletions
diff --git a/desktop/modules/git/gitcfg b/desktop/modules/git/gitcfg
index df955bf..a5641f7 100755
--- a/desktop/modules/git/gitcfg
+++ b/desktop/modules/git/gitcfg
@@ -13,7 +13,7 @@
#
# The global git config, for the drawer's git page.
#
-# gitcfg list git config --global -z --list
+# gitcfg list git config --global -z --list, or error=<why>
# gitcfg set <key> <old> <new> replace the one value equal to <old>
# gitcfg add <key> <value> add a value
# gitcfg unset <key> <value> remove the one value equal to <value>
@@ -39,16 +39,28 @@ g() {
err="$(git config --global "$@" 2>&1)" || { printf '%s\n' "${err:-git config failed}"; exit 1; }
}
-# --replace-all with no value equal to <old> appends <new> and succeeds, and
-# --unset of a missing value fails silently, so both check first: the file
-# may have changed in the editor since the page read it.
+# Exactly one value equal to <value>, or refuse. --replace-all with no match
+# appends <new> and succeeds, and --unset of a missing value fails silently:
+# the file may have changed in the editor since the page read it. With two
+# equal values --replace-all merges both rows into one and --unset fails, so a
+# duplicate is left to the editor.
has() {
- git config --global --fixed-value --get-all -- "$1" "$2" >/dev/null \
- || { printf '%s no longer holds that value\n' "$1"; exit 1; }
+ local n
+ n="$(git config --global -z --fixed-value --get-all -- "$1" "$2" | tr -cd '\0' | wc -c)"
+ case "$n" in
+ 1) ;;
+ 0) printf '%s no longer holds that value\n' "$1"; exit 1 ;;
+ *) printf '%s holds that value twice or more; use the editor\n' "$1"; exit 1 ;;
+ esac
}
case "${1:-}" in
- list) [[ $# -eq 1 ]] || usage; exec git config --global -z --list ;;
+ # A file git cannot parse prints nothing on stdout, which would read as
+ # an empty config, so its error comes out as one error= line instead.
+ list) [[ $# -eq 1 ]] || usage
+ err="$(git config --global --list 2>&1 >/dev/null)" \
+ || { printf 'error=%s\n' "${err:-git config failed}"; exit 1; }
+ exec git config --global -z --list ;;
set) [[ $# -eq 4 ]] || usage; has "$2" "$3"; g --fixed-value --replace-all -- "$2" "$4" "$3" ;;
add) [[ $# -eq 3 ]] || usage; g --add -- "$2" "$3" ;;
unset) [[ $# -eq 3 ]] || usage; has "$2" "$3"; g --fixed-value --unset -- "$2" "$3" ;;