git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 07/10] gitk: add keyboard bind for cherry-pick command

From
JGJens Lidestrom via GitGitGadget <gitgitgadget@gmail.com>
Date
Jul 3, 2023, 18:45 UTC
Message-ID
<54afa8fe9e831f5381d045bc24464ff2d6246118.1688409958.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.1551.v2.git.1688409958.gitgitgadget@gmail.com>
From: Jens Lidestrom <jens@lidestrom.se>
Signed-off-by: Jens Lidestrom <jens@lidestrom.se>
---
 gitk-git/gitk | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)
diff --git a/gitk-git/gitk b/gitk-git/gitk
index 65ca11becca..351b88f10c0 100755
--- a/gitk-git/gitk
+++ b/gitk-git/gitk
@@ -2690,6 +2690,7 @@ proc makewindow {} {
     bind $ctext $ctxbut {pop_diff_menu %W %X %Y %x %y}
     bind $ctext <Button-1> {focus %W}
     bind $ctext <<Selection>> rehighlight_search_results
+    bind . <$M1B-p> {cherrypick [selected_line_id]}
     bind . <$M1B-t> {resethead [selected_line_id]}
     bind . <$M1B-o> {checkout [selected_line_heads] [selected_line_id]}
     bind . <$M1B-m> {rmbranch [selected_line_heads] [selected_line_id] 1}
@@ -2710,8 +2711,8 @@ proc makewindow {} {
         {mc "Create tag" command mktag}
         {mc "Copy commit reference" command copyreference}
         {mc "Write commit to file" command writecommit}
-        {mc "Create new branch" command mkbranch}
-        {mc "Cherry-pick this commit" command cherrypick}
+        {mc "Create new branch" command {mkbranch $rowmenuid}}
+        {mc "Cherry-pick this commit" command {cherrypick $rowmenuid}}
         {mc "Reset current branch to here" command {resethead $rowmenuid}}
         {mc "Mark this commit" command markhere}
         {mc "Return to mark" command gotomark}
@@ -3186,6 +3187,7 @@ proc keys {} {
 [mc "<%s-minus>	Decrease font size" $M1T]
 [mc "<F5>		Update"]
 [mc "<%s-T>		Reset current branch to selected commit" $M1T]
+[mc "<%s-P>		Cherry-pick selected commit to current branch" $M1T]
 [mc "<%s-O>		Check out selected commit" $M1T]
 [mc "<%s-B>		Create branch on selected commit" $M1T]
 [mc "<%s-M>		Remove selected branch" $M1T]
@@ -9758,24 +9760,29 @@ proc exec_citool {tool_args {baseid {}}} {
     array set env $save_env
 }
 
-proc cherrypick {} {
-    global rowmenuid curview
+proc cherrypick {id} {
+    global curview headids
     global mainhead mainheadid
     global gitdir
 
+    if {! [info exists headids($mainhead)]} {
+        error_popup [mc "Cannot cherry-pick to a detached head"]
+        return
+    }
+
     set oldhead [exec git rev-parse HEAD]
-    set dheads [descheads $rowmenuid]
+    set dheads [descheads $id]
     if {$dheads ne {} && [lsearch -exact $dheads $oldhead] >= 0} {
         set ok [confirm_popup [mc "Commit %s is already\
                 included in branch %s -- really re-apply it?" \
-                                   [string range $rowmenuid 0 7] $mainhead]]
+                                   [string range $id 0 7] $mainhead]]
         if {!$ok} return
     }
     nowbusy cherrypick [mc "Cherry-picking"]
     update
     # Unfortunately git-cherry-pick writes stuff to stderr even when
     # no error occurs, and exec takes that as an indication of error...
-    if {[catch {exec sh -c "git cherry-pick -r $rowmenuid 2>&1"} err]} {
+    if {[catch {exec sh -c "git cherry-pick -r $id 2>&1"} err]} {
         notbusy cherrypick
         if {[regexp -line \
                  {Entry '(.*)' (would be overwritten by merge|not uptodate)} \
@@ -9791,7 +9798,7 @@ proc cherrypick {} {
                         resolve it?"]]} {
                 # Force citool to read MERGE_MSG
                 file delete [file join $gitdir "GITGUI_MSG"]
-                exec_citool {} $rowmenuid
+                exec_citool {} $id
             }
         } else {
             error_popup $err
-- 
gitgitgadget
Previous: Jens LideströmNext: Johannes Sixt
Message 35 of 42 in “gitk: improve keyboard support”
  1. 0/9 gitk: improve keyboard supportJens Lidestrom via GitGitGadget, Jun 27, 2023
  2. 1/9 gitk: add procedures to get commit info from selected rowJens Lidestrom via GitGitGadget, Jun 27, 2023
  3. 2/9 gitk: use term "current branch" in guiJens Lidestrom via GitGitGadget, Jun 27, 2023
  4. 3/9 gitk: add keyboard bind for resetJens Lidestrom via GitGitGadget, Jun 27, 2023
  5. 4/9 gitk: show branch name in reset dialogJens Lidestrom via GitGitGadget, Jun 27, 2023
  6. 5/9 gitk: add keyboard bind for checkoutJens Lidestrom via GitGitGadget, Jun 27, 2023
  7. Jens LideströmJul 2, 2023
  8. 6/9 gitk: add keyboard bind for create and remove branchJens Lidestrom via GitGitGadget, Jun 27, 2023
  9. Johannes SixtJun 28, 2023
  10. Jens LideströmJun 28, 2023
  11. Johannes SixtJun 28, 2023
  12. Jens LideströmJul 2, 2023
  13. 7/9 gitk: add keyboard bind to cherry-pickJens Lidestrom via GitGitGadget, Jun 27, 2023
  14. 8/9 gitk: focus ok button in reset dialogJens Lidestrom via GitGitGadget, Jun 27, 2023
  15. 9/9 gitk: default select reset hard in dialogJens Lidestrom via GitGitGadget, Jun 27, 2023
  16. Johannes SixtJun 28, 2023
  17. Jens LideströmJun 28, 2023
  18. Jens LideströmJul 2, 2023
  19. Johannes SixtJun 28, 2023
  20. Jens LideströmJun 28, 2023
  21. Jens LideströmJun 28, 2023
  22. Johannes SixtJun 28, 2023
  23. Jens LideströmJul 2, 2023
  24. 00/10 gitk: improve keyboard supportJens Lidestrom via GitGitGadget, Jul 3, 2023
  25. 01/10 gitk: add procedures to get commit info from selected rowJens Lidestrom via GitGitGadget, Jul 3, 2023
  26. 02/10 gitk: use term "current branch" in guiJens Lidestrom via GitGitGadget, Jul 3, 2023
  27. 03/10 gitk: add keyboard bind for reset commandJens Lidestrom via GitGitGadget, Jul 3, 2023
  28. 04/10 gitk: show branch name in reset dialogJens Lidestrom via GitGitGadget, Jul 3, 2023
  29. 06/10 gitk: add keyboard bind for remove branch commandJens Lidestrom via GitGitGadget, Jul 3, 2023
  30. Johannes SixtJul 5, 2023
  31. Jens LideströmJul 8, 2023
  32. 05/10 gitk: add keyboard bind for checkout commandJens Lidestrom via GitGitGadget, Jul 3, 2023
  33. Johannes SixtJul 5, 2023
  34. Jens LideströmJul 8, 2023
  35. 07/10 gitk: add keyboard bind for cherry-pick commandJens Lidestrom via GitGitGadget, Jul 3, 2023
  36. Johannes SixtJul 5, 2023
  37. Jens LideströmJul 8, 2023
  38. 08/10 gitk: add keyboard bind for create branch commandJens Lidestrom via GitGitGadget, Jul 3, 2023
  39. Johannes SixtJul 5, 2023
  40. 09/10 gitk: improve keyboard convenience in reset dialogJens Lidestrom via GitGitGadget, Jul 3, 2023
  41. Johannes SixtJul 5, 2023
  42. 10/10 gitk: allow checkout of remote branchJens Lidestrom via GitGitGadget, Jul 3, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.