blob: 0d81432af53ba873d89421fa4767243818ab1f0a [file] [log] [blame]
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -04001# git-gui misc. commit reading/writing support
2# Copyright (C) 2006, 2007 Shawn Pearce
3
4proc load_last_commit {} {
5 global HEAD PARENT MERGE_HEAD commit_type ui_comm
6 global repo_config
7
8 if {[llength $PARENT] == 0} {
Christian Stimming1ac17952007-07-21 14:21:34 +02009 error_popup [mc "There is nothing to amend.
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -040010
11You are about to create the initial commit. There is no commit before this to amend.
Christian Stimming1ac17952007-07-21 14:21:34 +020012"]
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -040013 return
14 }
15
16 repository_state curType curHEAD curMERGE_HEAD
17 if {$curType eq {merge}} {
Christian Stimming1ac17952007-07-21 14:21:34 +020018 error_popup [mc "Cannot amend while merging.
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -040019
20You are currently in the middle of a merge that has not been fully completed. You cannot amend the prior commit unless you first abort the current merge activity.
Christian Stimming1ac17952007-07-21 14:21:34 +020021"]
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -040022 return
23 }
24
25 set msg {}
26 set parents [list]
27 if {[catch {
Shawn O. Pearce0b812612007-07-09 01:17:09 -040028 set fd [git_read cat-file commit $curHEAD]
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -040029 fconfigure $fd -encoding binary -translation lf
Alexander Gavrilov3ac31e42008-12-06 20:24:35 +030030 # By default commits are assumed to be in utf-8
31 set enc utf-8
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -040032 while {[gets $fd line] > 0} {
33 if {[string match {parent *} $line]} {
34 lappend parents [string range $line 7 end]
35 } elseif {[string match {encoding *} $line]} {
36 set enc [string tolower [string range $line 9 end]]
37 }
38 }
Shawn O. Pearcec4638f62007-07-19 01:13:29 -040039 set msg [read $fd]
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -040040 close $fd
Shawn O. Pearcec4638f62007-07-19 01:13:29 -040041
42 set enc [tcl_encoding $enc]
43 if {$enc ne {}} {
44 set msg [encoding convertfrom $enc $msg]
45 }
46 set msg [string trim $msg]
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -040047 } err]} {
Shawn O. Pearce31bb1d12007-09-14 01:50:09 -040048 error_popup [strcat [mc "Error loading commit data for amend:"] "\n\n$err"]
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -040049 return
50 }
51
52 set HEAD $curHEAD
53 set PARENT $parents
54 set MERGE_HEAD [list]
55 switch -- [llength $parents] {
56 0 {set commit_type amend-initial}
57 1 {set commit_type amend}
58 default {set commit_type amend-merge}
59 }
60
61 $ui_comm delete 0.0 end
62 $ui_comm insert end $msg
63 $ui_comm edit reset
64 $ui_comm edit modified false
Shawn O. Pearce699d5602007-07-05 23:16:13 -040065 rescan ui_ready
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -040066}
67
68set GIT_COMMITTER_IDENT {}
69
70proc committer_ident {} {
71 global GIT_COMMITTER_IDENT
72
73 if {$GIT_COMMITTER_IDENT eq {}} {
74 if {[catch {set me [git var GIT_COMMITTER_IDENT]} err]} {
Shawn O. Pearce31bb1d12007-09-14 01:50:09 -040075 error_popup [strcat [mc "Unable to obtain your identity:"] "\n\n$err"]
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -040076 return {}
77 }
78 if {![regexp {^(.*) [0-9]+ [-+0-9]+$} \
79 $me me GIT_COMMITTER_IDENT]} {
Shawn O. Pearce31bb1d12007-09-14 01:50:09 -040080 error_popup [strcat [mc "Invalid GIT_COMMITTER_IDENT:"] "\n\n$me"]
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -040081 return {}
82 }
83 }
84
85 return $GIT_COMMITTER_IDENT
86}
87
88proc do_signoff {} {
89 global ui_comm
90
91 set me [committer_ident]
92 if {$me eq {}} return
93
94 set sob "Signed-off-by: $me"
95 set last [$ui_comm get {end -1c linestart} {end -1c}]
96 if {$last ne $sob} {
97 $ui_comm edit separator
98 if {$last ne {}
99 && ![regexp {^[A-Z][A-Za-z]*-[A-Za-z-]+: *} $last]} {
100 $ui_comm insert end "\n"
101 }
102 $ui_comm insert end "\n$sob"
103 $ui_comm edit separator
104 $ui_comm see end
105 }
106}
107
108proc create_new_commit {} {
109 global commit_type ui_comm
110
111 set commit_type normal
112 $ui_comm delete 0.0 end
113 $ui_comm edit reset
114 $ui_comm edit modified false
Shawn O. Pearce699d5602007-07-05 23:16:13 -0400115 rescan ui_ready
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400116}
117
Alexander Gavrilov06569cd2009-01-24 00:18:13 +0300118proc setup_commit_encoding {msg_wt {quiet 0}} {
119 global repo_config
120
121 if {[catch {set enc $repo_config(i18n.commitencoding)}]} {
122 set enc utf-8
123 }
124 set use_enc [tcl_encoding $enc]
125 if {$use_enc ne {}} {
126 fconfigure $msg_wt -encoding $use_enc
127 } else {
128 if {!$quiet} {
129 error_popup [mc "warning: Tcl does not support encoding '%s'." $enc]
130 }
131 fconfigure $msg_wt -encoding utf-8
132 }
133}
134
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400135proc commit_tree {} {
136 global HEAD commit_type file_states ui_comm repo_config
Shawn O. Pearce699d5602007-07-05 23:16:13 -0400137 global pch_error
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400138
139 if {[committer_ident] eq {}} return
140 if {![lock_index update]} return
141
142 # -- Our in memory state should match the repository.
143 #
144 repository_state curType curHEAD curMERGE_HEAD
145 if {[string match amend* $commit_type]
146 && $curType eq {normal}
147 && $curHEAD eq $HEAD} {
148 } elseif {$commit_type ne $curType || $HEAD ne $curHEAD} {
Christian Stimming1ac17952007-07-21 14:21:34 +0200149 info_popup [mc "Last scanned state does not match repository state.
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400150
151Another Git program has modified this repository since the last scan. A rescan must be performed before another commit can be created.
152
153The rescan will be automatically started now.
Christian Stimming1ac17952007-07-21 14:21:34 +0200154"]
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400155 unlock_index
Shawn O. Pearce699d5602007-07-05 23:16:13 -0400156 rescan ui_ready
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400157 return
158 }
159
160 # -- At least one file should differ in the index.
161 #
162 set files_ready 0
163 foreach path [array names file_states] {
Bert Wesarg4a065c82010-12-09 21:46:22 +0100164 set s $file_states($path)
165 switch -glob -- [lindex $s 0] {
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400166 _? {continue}
167 A? -
168 D? -
Bert Wesarg7587f4d2010-12-09 21:46:23 +0100169 T? -
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400170 M? {set files_ready 1}
Alexander Gavrilovff515d82008-08-31 01:00:49 +0400171 _U -
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400172 U? {
Christian Stimming1ac17952007-07-21 14:21:34 +0200173 error_popup [mc "Unmerged files cannot be committed.
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400174
Christian Stimming1ac17952007-07-21 14:21:34 +0200175File %s has merge conflicts. You must resolve them and stage the file before committing.
176" [short_path $path]]
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400177 unlock_index
178 return
179 }
180 default {
Christian Stimming1ac17952007-07-21 14:21:34 +0200181 error_popup [mc "Unknown file state %s detected.
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400182
Christian Stimming1ac17952007-07-21 14:21:34 +0200183File %s cannot be committed by this program.
184" [lindex $s 0] [short_path $path]]
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400185 }
186 }
187 }
Alexander Gavrilov1e65c622008-09-12 22:43:49 +0400188 if {!$files_ready && ![string match *merge $curType] && ![is_enabled nocommit]} {
Christian Stimming1ac17952007-07-21 14:21:34 +0200189 info_popup [mc "No changes to commit.
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400190
Christian Stimming360cc102007-07-28 22:17:10 +0200191You must stage at least 1 file before you can commit.
Christian Stimming1ac17952007-07-21 14:21:34 +0200192"]
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400193 unlock_index
194 return
195 }
196
Alexander Gavrilov1e65c622008-09-12 22:43:49 +0400197 if {[is_enabled nocommitmsg]} { do_quit 0 }
198
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400199 # -- A message is required.
200 #
201 set msg [string trim [$ui_comm get 1.0 end]]
202 regsub -all -line {[ \t\r]+$} $msg {} msg
203 if {$msg eq {}} {
Christian Stimming1ac17952007-07-21 14:21:34 +0200204 error_popup [mc "Please supply a commit message.
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400205
206A good commit message has the following format:
207
Michele Ballabio208320d2007-11-22 16:20:08 +0100208- First line: Describe in one sentence what you did.
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400209- Second line: Blank
210- Remaining lines: Describe why this change is good.
Christian Stimming1ac17952007-07-21 14:21:34 +0200211"]
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400212 unlock_index
213 return
214 }
215
Shawn O. Pearcefb0ca472008-01-20 14:11:52 -0500216 # -- Build the message file.
217 #
218 set msg_p [gitdir GITGUI_EDITMSG]
219 set msg_wt [open $msg_p w]
220 fconfigure $msg_wt -translation lf
Alexander Gavrilov06569cd2009-01-24 00:18:13 +0300221 setup_commit_encoding $msg_wt
Shawn O. Pearcefb0ca472008-01-20 14:11:52 -0500222 puts $msg_wt $msg
223 close $msg_wt
224
Alexander Gavrilov1e65c622008-09-12 22:43:49 +0400225 if {[is_enabled nocommit]} { do_quit 0 }
226
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400227 # -- Run the pre-commit hook.
228 #
Shawn O. Pearceed76cb72008-01-20 14:46:59 -0500229 set fd_ph [githook_read pre-commit]
230 if {$fd_ph eq {}} {
Shawn O. Pearcefb0ca472008-01-20 14:11:52 -0500231 commit_commitmsg $curHEAD $msg_p
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400232 return
233 }
234
Christian Stimming5e6d7762008-02-02 10:20:17 +0100235 ui_status [mc "Calling pre-commit hook..."]
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400236 set pch_error {}
Shawn O. Pearce6eb420e2007-07-17 01:50:10 -0400237 fconfigure $fd_ph -blocking 0 -translation binary -eofchar {}
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400238 fileevent $fd_ph readable \
Shawn O. Pearcefb0ca472008-01-20 14:11:52 -0500239 [list commit_prehook_wait $fd_ph $curHEAD $msg_p]
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400240}
241
Shawn O. Pearcefb0ca472008-01-20 14:11:52 -0500242proc commit_prehook_wait {fd_ph curHEAD msg_p} {
Shawn O. Pearce699d5602007-07-05 23:16:13 -0400243 global pch_error
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400244
245 append pch_error [read $fd_ph]
246 fconfigure $fd_ph -blocking 1
247 if {[eof $fd_ph]} {
248 if {[catch {close $fd_ph}]} {
Shawn O. Pearcefb0ca472008-01-20 14:11:52 -0500249 catch {file delete $msg_p}
Christian Stimming5e6d7762008-02-02 10:20:17 +0100250 ui_status [mc "Commit declined by pre-commit hook."]
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400251 hook_failed_popup pre-commit $pch_error
252 unlock_index
253 } else {
Shawn O. Pearcefb0ca472008-01-20 14:11:52 -0500254 commit_commitmsg $curHEAD $msg_p
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400255 }
256 set pch_error {}
257 return
258 }
259 fconfigure $fd_ph -blocking 0
260}
261
Shawn O. Pearcefb0ca472008-01-20 14:11:52 -0500262proc commit_commitmsg {curHEAD msg_p} {
Heiko Voigte34789c2011-02-15 19:43:54 +0000263 global is_detached repo_config
Shawn O. Pearcefb0ca472008-01-20 14:11:52 -0500264 global pch_error
265
Bert Wesargd8d166b2011-10-22 21:39:40 +0200266 if {$is_detached
267 && ![file exists [gitdir rebase-merge head-name]]
268 && [is_config_true gui.warndetachedcommit]} {
Heiko Voigte34789c2011-02-15 19:43:54 +0000269 set msg [mc "You are about to commit on a detached head.\
270This is a potentially dangerous thing to do because if you switch\
271to another branch you will loose your changes and it can be difficult\
272to retrieve them later from the reflog. You should probably cancel this\
273commit and create a new branch to continue.\n\
274\n\
275Do you really want to proceed with your Commit?"]
276 if {[ask_popup $msg] ne yes} {
277 unlock_index
278 return
279 }
280 }
281
Shawn O. Pearcefb0ca472008-01-20 14:11:52 -0500282 # -- Run the commit-msg hook.
283 #
Shawn O. Pearceed76cb72008-01-20 14:46:59 -0500284 set fd_ph [githook_read commit-msg $msg_p]
285 if {$fd_ph eq {}} {
Shawn O. Pearcefb0ca472008-01-20 14:11:52 -0500286 commit_writetree $curHEAD $msg_p
287 return
288 }
289
Christian Stimming5e6d7762008-02-02 10:20:17 +0100290 ui_status [mc "Calling commit-msg hook..."]
Shawn O. Pearcefb0ca472008-01-20 14:11:52 -0500291 set pch_error {}
Shawn O. Pearcefb0ca472008-01-20 14:11:52 -0500292 fconfigure $fd_ph -blocking 0 -translation binary -eofchar {}
293 fileevent $fd_ph readable \
294 [list commit_commitmsg_wait $fd_ph $curHEAD $msg_p]
295}
296
297proc commit_commitmsg_wait {fd_ph curHEAD msg_p} {
298 global pch_error
299
300 append pch_error [read $fd_ph]
301 fconfigure $fd_ph -blocking 1
302 if {[eof $fd_ph]} {
303 if {[catch {close $fd_ph}]} {
304 catch {file delete $msg_p}
Christian Stimming5e6d7762008-02-02 10:20:17 +0100305 ui_status [mc "Commit declined by commit-msg hook."]
Shawn O. Pearcefb0ca472008-01-20 14:11:52 -0500306 hook_failed_popup commit-msg $pch_error
307 unlock_index
308 } else {
309 commit_writetree $curHEAD $msg_p
310 }
311 set pch_error {}
312 return
313 }
314 fconfigure $fd_ph -blocking 0
315}
316
317proc commit_writetree {curHEAD msg_p} {
Christian Stimming5e6d7762008-02-02 10:20:17 +0100318 ui_status [mc "Committing changes..."]
Shawn O. Pearce0b812612007-07-09 01:17:09 -0400319 set fd_wt [git_read write-tree]
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400320 fileevent $fd_wt readable \
Shawn O. Pearcefb0ca472008-01-20 14:11:52 -0500321 [list commit_committree $fd_wt $curHEAD $msg_p]
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400322}
323
Shawn O. Pearcefb0ca472008-01-20 14:11:52 -0500324proc commit_committree {fd_wt curHEAD msg_p} {
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400325 global HEAD PARENT MERGE_HEAD commit_type
Shawn O. Pearce699d5602007-07-05 23:16:13 -0400326 global current_branch
327 global ui_comm selected_commit_type
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400328 global file_states selected_paths rescan_active
329 global repo_config
330
331 gets $fd_wt tree_id
Shawn O. Pearce8af52d72007-10-20 01:42:01 -0400332 if {[catch {close $fd_wt} err]} {
Shawn O. Pearcefb0ca472008-01-20 14:11:52 -0500333 catch {file delete $msg_p}
Shawn O. Pearce31bb1d12007-09-14 01:50:09 -0400334 error_popup [strcat [mc "write-tree failed:"] "\n\n$err"]
Christian Stimming5e6d7762008-02-02 10:20:17 +0100335 ui_status [mc "Commit failed."]
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400336 unlock_index
337 return
338 }
339
340 # -- Verify this wasn't an empty change.
341 #
342 if {$commit_type eq {normal}} {
Shawn O. Pearceb2158832007-07-12 02:45:23 -0400343 set fd_ot [git_read cat-file commit $PARENT]
Shawn O. Pearce20f1a102007-07-12 02:31:28 -0400344 fconfigure $fd_ot -encoding binary -translation lf
345 set old_tree [gets $fd_ot]
346 close $fd_ot
347
348 if {[string equal -length 5 {tree } $old_tree]
349 && [string length $old_tree] == 45} {
350 set old_tree [string range $old_tree 5 end]
351 } else {
Michele Ballabioc8c48542007-09-13 15:19:05 +0200352 error [mc "Commit %s appears to be corrupt" $PARENT]
Shawn O. Pearce20f1a102007-07-12 02:31:28 -0400353 }
354
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400355 if {$tree_id eq $old_tree} {
Shawn O. Pearcefb0ca472008-01-20 14:11:52 -0500356 catch {file delete $msg_p}
Christian Stimming1ac17952007-07-21 14:21:34 +0200357 info_popup [mc "No changes to commit.
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400358
359No files were modified by this commit and it was not a merge commit.
360
361A rescan will be automatically started now.
Christian Stimming1ac17952007-07-21 14:21:34 +0200362"]
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400363 unlock_index
Christian Stimming1ac17952007-07-21 14:21:34 +0200364 rescan {ui_status [mc "No changes to commit."]}
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400365 return
366 }
367 }
368
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400369 # -- Create the commit.
370 #
371 set cmd [list commit-tree $tree_id]
372 foreach p [concat $PARENT $MERGE_HEAD] {
373 lappend cmd -p $p
374 }
375 lappend cmd <$msg_p
376 if {[catch {set cmt_id [eval git $cmd]} err]} {
Shawn O. Pearcefb0ca472008-01-20 14:11:52 -0500377 catch {file delete $msg_p}
Shawn O. Pearce31bb1d12007-09-14 01:50:09 -0400378 error_popup [strcat [mc "commit-tree failed:"] "\n\n$err"]
Christian Stimming5e6d7762008-02-02 10:20:17 +0100379 ui_status [mc "Commit failed."]
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400380 unlock_index
381 return
382 }
383
384 # -- Update the HEAD ref.
385 #
386 set reflogm commit
387 if {$commit_type ne {normal}} {
388 append reflogm " ($commit_type)"
389 }
Shawn O. Pearcefb0ca472008-01-20 14:11:52 -0500390 set msg_fd [open $msg_p r]
Alexander Gavrilov06569cd2009-01-24 00:18:13 +0300391 setup_commit_encoding $msg_fd 1
Shawn O. Pearcefb0ca472008-01-20 14:11:52 -0500392 gets $msg_fd subject
393 close $msg_fd
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400394 append reflogm {: } $subject
395 if {[catch {
396 git update-ref -m $reflogm HEAD $cmt_id $curHEAD
397 } err]} {
Shawn O. Pearcefb0ca472008-01-20 14:11:52 -0500398 catch {file delete $msg_p}
Shawn O. Pearce31bb1d12007-09-14 01:50:09 -0400399 error_popup [strcat [mc "update-ref failed:"] "\n\n$err"]
Christian Stimming5e6d7762008-02-02 10:20:17 +0100400 ui_status [mc "Commit failed."]
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400401 unlock_index
402 return
403 }
404
405 # -- Cleanup after ourselves.
406 #
407 catch {file delete $msg_p}
408 catch {file delete [gitdir MERGE_HEAD]}
409 catch {file delete [gitdir MERGE_MSG]}
410 catch {file delete [gitdir SQUASH_MSG]}
411 catch {file delete [gitdir GITGUI_MSG]}
412
413 # -- Let rerere do its thing.
414 #
Shawn O. Pearced4c53072007-07-08 17:41:24 -0400415 if {[get_config rerere.enabled] eq {}} {
416 set rerere [file isdirectory [gitdir rr-cache]]
417 } else {
418 set rerere [is_config_true rerere.enabled]
419 }
420 if {$rerere} {
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400421 catch {git rerere}
422 }
423
424 # -- Run the post-commit hook.
425 #
Shawn O. Pearceed76cb72008-01-20 14:46:59 -0500426 set fd_ph [githook_read post-commit]
427 if {$fd_ph ne {}} {
Jens Lehmannf0d4eec2009-03-30 20:35:57 +0200428 global pch_error
429 set pch_error {}
Shawn O. Pearceed76cb72008-01-20 14:46:59 -0500430 fconfigure $fd_ph -blocking 0 -translation binary -eofchar {}
431 fileevent $fd_ph readable \
432 [list commit_postcommit_wait $fd_ph $cmt_id]
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400433 }
434
435 $ui_comm delete 0.0 end
436 $ui_comm edit reset
437 $ui_comm edit modified false
Shawn O. Pearce4578c5c2007-07-21 04:57:57 -0400438 if {$::GITGUI_BCK_exists} {
439 catch {file delete [gitdir GITGUI_BCK]}
Shawn O. Pearce9c5a3c72007-07-23 00:20:04 -0400440 set ::GITGUI_BCK_exists 0
Shawn O. Pearce4578c5c2007-07-21 04:57:57 -0400441 }
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400442
Alexander Gavrilov1e65c622008-09-12 22:43:49 +0400443 if {[is_enabled singlecommit]} { do_quit 0 }
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400444
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400445 # -- Update in memory status
446 #
447 set selected_commit_type new
448 set commit_type normal
449 set HEAD $cmt_id
450 set PARENT $cmt_id
451 set MERGE_HEAD [list]
452
453 foreach path [array names file_states] {
454 set s $file_states($path)
455 set m [lindex $s 0]
456 switch -glob -- $m {
457 _O -
458 _M -
459 _D {continue}
460 __ -
461 A_ -
462 M_ -
Gustaf Hendebye681cb72008-08-22 22:10:27 +0200463 T_ -
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400464 D_ {
465 unset file_states($path)
466 catch {unset selected_paths($path)}
467 }
468 DO {
469 set file_states($path) [list _O [lindex $s 1] {} {}]
470 }
471 AM -
472 AD -
Bert Wesarg7587f4d2010-12-09 21:46:23 +0100473 AT -
474 TM -
475 TD -
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400476 MM -
Bert Wesarg7587f4d2010-12-09 21:46:23 +0100477 MT -
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400478 MD {
479 set file_states($path) [list \
480 _[string index $m 1] \
481 [lindex $s 1] \
482 [lindex $s 3] \
483 {}]
484 }
485 }
486 }
487
488 display_all_files
489 unlock_index
490 reshow_diff
Christian Stimming1ac17952007-07-21 14:21:34 +0200491 ui_status [mc "Created commit %s: %s" [string range $cmt_id 0 7] $subject]
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400492}
Shawn O. Pearceed76cb72008-01-20 14:46:59 -0500493
494proc commit_postcommit_wait {fd_ph cmt_id} {
Jens Lehmannf0d4eec2009-03-30 20:35:57 +0200495 global pch_error
Shawn O. Pearceed76cb72008-01-20 14:46:59 -0500496
497 append pch_error [read $fd_ph]
498 fconfigure $fd_ph -blocking 1
499 if {[eof $fd_ph]} {
500 if {[catch {close $fd_ph}]} {
501 hook_failed_popup post-commit $pch_error 0
502 }
503 unset pch_error
504 return
505 }
506 fconfigure $fd_ph -blocking 0
507}