GithubHelp home page GithubHelp logo

Comments (7)

scscgit avatar scscgit commented on June 15, 2024 2

This is the most serious issue of the entire Git GUI! And I'm sure that it also happens under different circumstances (maybe after a Rescan when some other operations have been done in parallel, but I can't deliberately reproduce it). We need some form of commit message history, even for the scenarios when you screw up the Undo & Redo at a wrong moment. And obviously, even if you ignore power outages & Windows stability, one of the reasons why this is a must have is the frequency of Git GUI (wish.exe) freezing up.

from git-gui.

annulen avatar annulen commented on June 15, 2024 1

Presumably we want to add confirmation/auto-save of message text before deleting/clearing message text.

I think it would make more sense to use two separate backup files for "amended" and "new" messages, and clear respective backup when commit is done. Works intuitively and no need to confirm anything.

from git-gui.

annulen avatar annulen commented on June 15, 2024

Most user-friendly solution would be to keep old commit message in temporary file or just stored in memory in variable, and put it back into editor if user switches back from amend mode.

Less user-friendly but still OK is to show a confirmation dialog if "Amend Last Commit" is clicked and there is a text to be destroyed

from git-gui.

follower avatar follower commented on June 15, 2024

Some additional information which might be useful to someone trying to implement this (based on some brief code spelunking):

  • While running, it appears a backup of the current text of the commit message UI control is stored in .git/GITGUI_BCK.
  • The above backup file seems to be created via a procedure named backup_commit_buffer:

    git-gui/git-gui.sh

    Lines 4122 to 4151 in df4f9e2

    proc backup_commit_buffer {} {
    global ui_comm GITGUI_BCK_exists
    set m [$ui_comm edit modified]
    if {$m || $GITGUI_BCK_exists} {
    set msg [string trim [$ui_comm get 0.0 end]]
    regsub -all -line {[ \r\t]+$} $msg {} msg
    if {$msg eq {}} {
    if {$GITGUI_BCK_exists} {
    catch {file delete [gitdir GITGUI_BCK]}
    set GITGUI_BCK_exists 0
    }
    } elseif {$m} {
    catch {
    set fd [open [gitdir GITGUI_BCK] w]
    fconfigure $fd -encoding utf-8
    puts -nonewline $fd $msg
    close $fd
    set GITGUI_BCK_exists 1
    }
    }
    $ui_comm edit modified false
    }
    set ::GITGUI_BCK_i [after 2000 backup_commit_buffer]
    }
    backup_commit_buffer
  • The name of the commit message UI control appears to be ui_comm also referred to as $ui_comm.
  • It appears that the current commit message text is also stored in .git/GITGUI_MSG if it is non-empty when the program exits.
  • See also:
    • git-gui/git-gui.sh

      Lines 4100 to 4120 in df4f9e2

      if {[winfo exists $ui_comm]} {
      set GITGUI_BCK_exists [load_message GITGUI_BCK utf-8]
      # -- If both our backup and message files exist use the
      # newer of the two files to initialize the buffer.
      #
      if {$GITGUI_BCK_exists} {
      set m [gitdir GITGUI_MSG]
      if {[file isfile $m]} {
      if {[file mtime [gitdir GITGUI_BCK]] > [file mtime $m]} {
      catch {file delete [gitdir GITGUI_MSG]}
      } else {
      $ui_comm delete 0.0 end
      $ui_comm edit reset
      $ui_comm edit modified false
      catch {file delete [gitdir GITGUI_BCK]}
      set GITGUI_BCK_exists 0
      }
      }
      unset m
      }
    • git-gui/git-gui.sh

      Lines 3924 to 3949 in df4f9e2

      # -- Key Bindings
      #
      bind $ui_comm <$M1B-Key-Return> {do_commit;break}
      bind $ui_comm <$M1B-Key-t> {do_add_selection;break}
      bind $ui_comm <$M1B-Key-T> {do_add_selection;break}
      bind $ui_comm <$M1B-Key-u> {do_unstage_selection;break}
      bind $ui_comm <$M1B-Key-U> {do_unstage_selection;break}
      bind $ui_comm <$M1B-Key-j> {do_revert_selection;break}
      bind $ui_comm <$M1B-Key-J> {do_revert_selection;break}
      bind $ui_comm <$M1B-Key-i> {do_add_all;break}
      bind $ui_comm <$M1B-Key-I> {do_add_all;break}
      bind $ui_comm <$M1B-Key-x> {tk_textCut %W;break}
      bind $ui_comm <$M1B-Key-X> {tk_textCut %W;break}
      bind $ui_comm <$M1B-Key-c> {tk_textCopy %W;break}
      bind $ui_comm <$M1B-Key-C> {tk_textCopy %W;break}
      bind $ui_comm <$M1B-Key-v> {tk_textPaste %W; %W see insert; break}
      bind $ui_comm <$M1B-Key-V> {tk_textPaste %W; %W see insert; break}
      bind $ui_comm <$M1B-Key-a> {%W tag add sel 0.0 end;break}
      bind $ui_comm <$M1B-Key-A> {%W tag add sel 0.0 end;break}
      bind $ui_comm <$M1B-Key-minus> {show_less_context;break}
      bind $ui_comm <$M1B-Key-KP_Subtract> {show_less_context;break}
      bind $ui_comm <$M1B-Key-equal> {show_more_context;break}
      bind $ui_comm <$M1B-Key-plus> {show_more_context;break}
      bind $ui_comm <$M1B-Key-KP_Add> {show_more_context;break}
      bind $ui_comm <$M1B-Key-BackSpace> {event generate %W <Meta-Delete>;break}
      bind $ui_comm <$M1B-Key-Delete> {event generate %W <Meta-d>;break}
    • git-gui/git-gui.sh

      Lines 3475 to 3506 in df4f9e2

      # -- Commit Message Buffer Context Menu
      #
      set ctxm .vpane.lower.commarea.buffer.ctxm
      menu $ctxm -tearoff 0
      $ctxm add command \
      -label [mc Cut] \
      -command {tk_textCut $ui_comm}
      $ctxm add command \
      -label [mc Copy] \
      -command {tk_textCopy $ui_comm}
      $ctxm add command \
      -label [mc Paste] \
      -command {tk_textPaste $ui_comm}
      $ctxm add command \
      -label [mc Delete] \
      -command {catch {$ui_comm delete sel.first sel.last}}
      $ctxm add separator
      $ctxm add command \
      -label [mc "Select All"] \
      -command {focus $ui_comm;$ui_comm tag add sel 0.0 end}
      $ctxm add command \
      -label [mc "Copy All"] \
      -command {
      $ui_comm tag add sel 0.0 end
      tk_textCopy $ui_comm
      $ui_comm tag remove sel 0.0 end
      }
      $ctxm add separator
      $ctxm add command \
      -label [mc "Sign Off"] \
      -command do_signoff
      set ui_comm_ctxm $ctxm
    • git-gui/git-gui.sh

      Lines 3448 to 3466 in df4f9e2

      textframe .vpane.lower.commarea.buffer.frame
      ttext $ui_comm \
      -borderwidth 1 \
      -undo true \
      -maxundo 20 \
      -autoseparators true \
      -takefocus 1 \
      -highlightthickness 1 \
      -relief sunken \
      -width $repo_config(gui.commitmsgwidth) -height 9 -wrap none \
      -font font_diff \
      -xscrollcommand {.vpane.lower.commarea.buffer.frame.sbx set} \
      -yscrollcommand {.vpane.lower.commarea.buffer.frame.sby set}
      ${NS}::scrollbar .vpane.lower.commarea.buffer.frame.sbx \
      -orient horizontal \
      -command [list $ui_comm xview]
      ${NS}::scrollbar .vpane.lower.commarea.buffer.frame.sby \
      -orient vertical \
      -command [list $ui_comm yview]
    • git-gui/git-gui.sh

      Lines 2719 to 2723 in df4f9e2

      ######################################################################
      ##
      ## ui construction
      set ui_comm {}
    • git-gui/git-gui.sh

      Lines 1474 to 1486 in df4f9e2

      if {!$::GITGUI_BCK_exists &&
      (![$ui_comm edit modified]
      || [string trim [$ui_comm get 0.0 end]] eq {})} {
      if {[string match amend* $commit_type]} {
      } elseif {[load_message GITGUI_MSG utf-8]} {
      } elseif {[run_prepare_commit_msg_hook]} {
      } elseif {[load_message MERGE_MSG]} {
      } elseif {[load_message SQUASH_MSG]} {
      } elseif {[load_message [get_config commit.template]]} {
      }
      $ui_comm edit reset
      $ui_comm edit modified false
      }
    • git-gui/git-gui.sh

      Lines 1574 to 1594 in df4f9e2

      proc load_message {file {encoding {}}} {
      global ui_comm
      set f [gitdir $file]
      if {[file isfile $f]} {
      if {[catch {set fd [open $f r]}]} {
      return 0
      }
      fconfigure $fd -eofchar {}
      if {$encoding ne {}} {
      fconfigure $fd -encoding $encoding
      }
      set content [string trim [read $fd]]
      close $fd
      regsub -all -line {[ \r\t]+$} $content {} content
      $ui_comm delete 0.0 end
      $ui_comm insert end $content
      return 1
      }
      return 0
      }
    • git-gui/git-gui.sh

      Lines 2305 to 2339 in df4f9e2

      if {[winfo exists $ui_comm]} {
      # -- Stash our current commit buffer.
      #
      set save [gitdir GITGUI_MSG]
      if {$GITGUI_BCK_exists && ![$ui_comm edit modified]} {
      file rename -force [gitdir GITGUI_BCK] $save
      set GITGUI_BCK_exists 0
      } elseif {[$ui_comm edit modified]} {
      set msg [string trim [$ui_comm get 0.0 end]]
      regsub -all -line {[ \r\t]+$} $msg {} msg
      if {![string match amend* $commit_type]
      && $msg ne {}} {
      catch {
      set fd [open $save w]
      fconfigure $fd -encoding utf-8
      puts -nonewline $fd $msg
      close $fd
      }
      } else {
      catch {file delete $save}
      }
      }
      # -- Cancel our spellchecker if its running.
      #
      if {[info exists ui_comm_spell]} {
      $ui_comm_spell stop
      }
      # -- Remove our editor backup, its not needed.
      #
      after cancel $GITGUI_BCK_i
      if {$GITGUI_BCK_exists} {
      catch {file delete [gitdir GITGUI_BCK]}
      }
    • (Clears message text.)

      git-gui/lib/commit.tcl

      Lines 69 to 73 in df4f9e2

      $ui_comm delete 0.0 end
      $ui_comm insert end $msg
      $ui_comm edit reset
      $ui_comm edit modified false
      rescan ui_ready
    • (Clears message text.)

      git-gui/lib/commit.tcl

      Lines 121 to 123 in df4f9e2

      $ui_comm delete 0.0 end
      $ui_comm edit reset
      $ui_comm edit modified false
  • Presumably we want to add confirmation/auto-save of message text before deleting/clearing message text.
  • In the interim, it might be a sufficient workaround to disable the "amend" etc button when the commit message text area isn't empty?

Hope these are some useful pointers for someone. :)

from git-gui.

annulen avatar annulen commented on June 15, 2024

GITGUI_BCK was introduced in 4578c5c, commit message contains details how GITGUI_BCK and GITGUI_MSG files are used

from git-gui.

annulen avatar annulen commented on June 15, 2024

I think it would make more sense to use two separate backup files for "amended" and "new" messages, and clear respective backup when commit is done. Works intuitively and no need to confirm anything.

Actually, it's not that simple, as "amended" message becomes irrelevant after HEAD moves. I see two possible ways to handle this situation:

  1. Don't backup "amended" message at all, so editing in "amend" mode always starts from original message. It's simpler to implement and is easy to understand, though may cause a loss of work if non-trivial edits were done in "amend" mode.
  2. Do backup "amended" message, but save corresponding HEAD hash alongside, drop it if current HEAD is different.

from git-gui.

annulen avatar annulen commented on June 15, 2024

git citool --amend doesn't restore message from GITGUI_MSG, so I guess doing #1 would not be a step back in functionality.

from git-gui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.