From e97d5dea1d2b36ee9882de8699b382cf4fef64ae Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Fri, 16 Oct 2026 11:22:41 +0200 Subject: 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 --- desktop/modules/git/gitcfg | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'desktop/modules/git/gitcfg') 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= # gitcfg set replace the one value equal to # gitcfg add add a value # gitcfg unset remove the one value equal to @@ -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 appends 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 , or refuse. --replace-all with no match +# appends 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" ;; -- cgit v1.2.3