Skip to content

Commit cfe616b

Browse files
committed
git-gui: avoid persisting modified author identity
Commit 7e71adc fixes a problem with git-gui failing to pick up the original author identity during a commit --amend operation. However, the new author details then become persistent for the remainder of the session. This commit fixes this by ensuring the environment variables are reset and the author information reset once the commit is completed. The relevant changes were reworked to reduce global variables. Signed-off-by: Pat Thoyts <[email protected]>
1 parent 7e71adc commit cfe616b

File tree

1 file changed

+31
-20
lines changed

1 file changed

+31
-20
lines changed

lib/commit.tcl

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
# git-gui misc. commit reading/writing support
22
# Copyright (C) 2006, 2007 Shawn Pearce
33

4-
set author_name ""
5-
set author_email ""
6-
set author_date ""
7-
84
proc load_last_commit {} {
9-
global HEAD PARENT MERGE_HEAD commit_type ui_comm
10-
global author_name author_email author_date
5+
global HEAD PARENT MERGE_HEAD commit_type ui_comm commit_author
116
global repo_config
127

138
if {[llength $PARENT] == 0} {
@@ -40,9 +35,7 @@ You are currently in the middle of a merge that has not been fully completed. Y
4035
} elseif {[string match {encoding *} $line]} {
4136
set enc [string tolower [string range $line 9 end]]
4237
} elseif {[regexp "author (.*)\\s<(.*)>\\s(\\d.*$)" $line all name email time]} {
43-
set author_name $name
44-
set author_email $email
45-
set author_date $time
38+
set commit_author [list name $name email $email date $time]
4639
}
4740
}
4841
set msg [read $fd]
@@ -115,13 +108,10 @@ proc do_signoff {} {
115108
}
116109

117110
proc create_new_commit {} {
118-
global commit_type ui_comm
119-
global author_name author_email author_date
111+
global commit_type ui_comm commit_author
120112

121113
set commit_type normal
122-
set author_name ""
123-
set author_email ""
124-
set author_date ""
114+
unset -nocomplain commit_author
125115
$ui_comm delete 0.0 end
126116
$ui_comm edit reset
127117
$ui_comm edit modified false
@@ -335,12 +325,12 @@ proc commit_writetree {curHEAD msg_p} {
335325
}
336326

337327
proc commit_committree {fd_wt curHEAD msg_p} {
338-
global HEAD PARENT MERGE_HEAD commit_type
328+
global HEAD PARENT MERGE_HEAD commit_type commit_author
339329
global current_branch
340330
global ui_comm selected_commit_type
341331
global file_states selected_paths rescan_active
342332
global repo_config
343-
global env author_name author_email author_date
333+
global env
344334

345335
gets $fd_wt tree_id
346336
if {[catch {close $fd_wt} err]} {
@@ -380,10 +370,8 @@ A rescan will be automatically started now.
380370
}
381371
}
382372

383-
if {$author_name ne ""} {
384-
set env(GIT_AUTHOR_NAME) $author_name
385-
set env(GIT_AUTHOR_EMAIL) $author_email
386-
set env(GIT_AUTHOR_DATE) $author_date
373+
if {[info exists commit_author]} {
374+
set old_author [commit_author_ident $commit_author]
387375
}
388376
# -- Create the commit.
389377
#
@@ -397,8 +385,14 @@ A rescan will be automatically started now.
397385
error_popup [strcat [mc "commit-tree failed:"] "\n\n$err"]
398386
ui_status [mc "Commit failed."]
399387
unlock_index
388+
unset -nocomplain commit_author
389+
commit_author_reset $old_author
400390
return
401391
}
392+
if {[info exists commit_author]} {
393+
unset -nocomplain commit_author
394+
commit_author_reset $old_author
395+
}
402396

403397
# -- Update the HEAD ref.
404398
#
@@ -525,3 +519,20 @@ proc commit_postcommit_wait {fd_ph cmt_id} {
525519
}
526520
fconfigure $fd_ph -blocking 0
527521
}
522+
523+
proc commit_author_ident {details} {
524+
global env
525+
array set author $details
526+
set old [array get env GIT_AUTHOR_*]
527+
set env(GIT_AUTHOR_NAME) $author(name)
528+
set env(GIT_AUTHOR_EMAIL) $author(email)
529+
set env(GIT_AUTHOR_DATE) $author(date)
530+
return $old
531+
}
532+
proc commit_author_reset {details} {
533+
global env
534+
unset env(GIT_AUTHOR_NAME) env(GIT_AUTHOR_EMAIL) env(GIT_AUTHOR_DATE)
535+
if {$details ne {}} {
536+
array set env $details
537+
}
538+
}

0 commit comments

Comments
 (0)