git/lib
Johannes Sixt c461528cd4 git-gui: fix error handling of Revert Changes command
The command Revert Changes has two different erroneous behaviors
depending on the Tcl version used.

The command uses a "chord" facility where different "notes" are
evaluated asynchronously and any error is reported after all of them
have finished. The intent is that a private namespace is used where
the notes can store the error state. Tcl 9 changed namespace handling
in a subtle way, as https://www.tcl-lang.org/software/tcltk/9.0.html
summarizes under "Notable incompatibilities":

    Unqualified varnames resolved in current namespace, not global.
    Note that in almost all cases where this causes a change, the
    change is actually the removal of a latent bug.

And that's exactly what happens here.

- Under Tcl 9:

  - When the command operates without any errors, the variable `err`
    is never set. When the error handler wants to inspect `err` (in
    the correct private namespace), it does not find it and a Tcl
    error about an unset variable occurs. Incidentally, this is also
    the case when the user cancels the operation with the option
    "Do Nothing"!

    On the other hand, when an error occurs during the operation, `err`
    is set and found as intended.

  Check for the existence of the variable `err` before the attempt to
  read it.

- Under Tcl 8.6:

  The error handler looks up `err` in the global namespace, which is
  bogus and unintended. The variable is set due to the many
  `catch ... err` that occur during startup in the global namespace.

  - When the command operates without any errors, the error handler
    finds the global `err`, which happens to be the empty string at
    this point, and no error is reported.

    On the other hand, when an error occurs during the operation, the
    global `err` is set and found, so that an error is reported as
    desired.

    However, the value of `err` persists in the global namespace. When
    the command is repeated, an error is reported again, even if there
    was actually no error, and even "Do Nothing" was used to cancel
    the operation.

  Clear the global `err` before the operation begins.

The lingering error message is not a problem under Tcl 9, because a
prestine namespace is established every time the command is used.

This fixes https://github.com/j6t/git-gui/issues/21.

Helped-by: Igor Stepushchik
Signed-off-by: Johannes Sixt <j6t@kdbg.org>
2025-09-01 21:07:57 +02:00
..
about.tcl Merge branch 'ml/abandon-old-versions' 2025-07-22 17:37:33 +02:00
blame.tcl git-gui: use -profile tcl8 on encoding conversions 2025-07-31 13:51:03 -04:00
branch.tcl git-gui: do not mix -translation binary and -encoding 2025-07-22 12:32:58 -04:00
branch_checkout.tcl git-gui: remove non-ttk code 2025-07-21 11:59:21 -04:00
branch_create.tcl git-gui: remove non-ttk code 2025-07-21 11:59:21 -04:00
branch_delete.tcl git-gui: remove non-ttk code 2025-07-21 11:59:21 -04:00
branch_rename.tcl git-gui: remove non-ttk code 2025-07-21 11:59:21 -04:00
browser.tcl git-gui: do not mix -translation binary and -encoding 2025-07-22 12:32:58 -04:00
checkout_op.tcl git-gui: assure -eofchar {} on all channels 2025-07-22 12:32:58 -04:00
choose_font.tcl git-gui: remove non-ttk code 2025-07-21 11:59:21 -04:00
choose_repository.tcl Merge branch 'ml/abandon-old-versions' 2025-07-22 17:37:33 +02:00
choose_rev.tcl git-gui: remove EOL translation for gets 2025-07-31 13:50:59 -04:00
chord.tcl git-gui: create a new namespace for chord script evaluation 2020-03-17 18:48:54 +05:30
class.tcl git-gui: remove non-ttk code 2025-07-21 11:59:21 -04:00
commit.tcl Merge branch 'strip-post-hooks' of github.com:orgads/git-gui 2025-08-02 14:45:19 +02:00
console.tcl git-gui: remove non-ttk code 2025-07-21 11:59:21 -04:00
database.tcl git-gui: remove non-ttk code 2025-07-21 11:59:21 -04:00
date.tcl git-gui: Localize commit/author dates when displaying them 2007-09-10 01:54:16 -04:00
diff.tcl git-gui: remove EOL translation for gets 2025-07-31 13:50:59 -04:00
encoding.tcl doc: switch links to https 2024-05-05 16:49:00 +02:00
error.tcl git-gui: remove non-ttk code 2025-07-21 11:59:21 -04:00
git-gui.ico git-gui: Improve the application icon on Windows. 2007-12-02 23:05:10 -05:00
index.tcl git-gui: fix error handling of Revert Changes command 2025-09-01 21:07:57 +02:00
line.tcl git-gui: remove non-ttk code 2025-07-21 11:59:21 -04:00
logo.tcl git-gui: Refactor Henrik Nyh's logo into its own procedure 2007-10-10 01:12:15 -04:00
merge.tcl Merge branch 'ml/abandon-old-versions' 2025-07-22 17:37:33 +02:00
mergetool.tcl git-gui: translation binary defines iso8859-1 2025-07-22 12:32:58 -04:00
meson.build git-gui: wire up support for the Meson build system 2025-05-13 08:48:09 +02:00
option.tcl git-gui: remove non-ttk code 2025-07-21 11:59:21 -04:00
remote.tcl git-gui: git-remote is always available 2025-07-18 23:48:06 -04:00
remote_add.tcl git-gui: remove non-ttk code 2025-07-21 11:59:21 -04:00
remote_branch_delete.tcl git-gui: remove EOL translation for gets 2025-07-31 13:50:59 -04:00
search.tcl git-gui: remove non-ttk code 2025-07-21 11:59:21 -04:00
shortcut.tcl git-gui: use /cmd/git-gui.exe for shortcut 2025-07-22 10:21:44 -04:00
spellcheck.tcl git-gui: assure -eofchar {} on all channels 2025-07-22 12:32:58 -04:00
sshkey.tcl git-gui: remove non-ttk code 2025-07-21 11:59:21 -04:00
status_bar.tcl git-gui: remove non-ttk code 2025-07-21 11:59:21 -04:00
themed.tcl git-gui: themed.tcl: use full namespace for color 2025-07-31 13:51:03 -04:00
tools.tcl Merge branch 'ml/replace-auto-execok' into js/fix-open-exec 2025-05-23 17:04:27 -04:00
tools_dlg.tcl git-gui: remove non-ttk code 2025-07-21 11:59:21 -04:00
transport.tcl git-gui: remove non-ttk code 2025-07-21 11:59:21 -04:00
win32.tcl git-gui: sanitize 'exec' arguments: simple cases 2025-05-23 17:04:23 -04:00
win32_shortcut.js git-gui: Use proper Windows shortcuts instead of bat files 2007-10-12 23:07:58 -04:00