Anonymous avatar Anonymous committed d4e890e

git-gui: Make sure we get errors from git-update-index

I'm seeing a lot of silent failures from git-update-index on
Windows and this is leaving the index.lock file intact, which
means users are later unable to perform additional operations.

When the index is locked behind our back and we are unable to
use it we may need to allow the user to delete the index lock
and try again. However our UI state is probably not currect
as we have assumed that some changes were applied but none of
them actually did. A rescan is the easiest (in code anyway)
solution to correct our UI to show what the index really has
(or doesn't have).

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>;

Comments (0)

Files changed (1)

 # git-gui index (add/remove) support
 # Copyright (C) 2006, 2007 Shawn Pearce
 
+proc _delete_indexlock {} {
+	if {[catch {file delete -- [gitdir index.lock]} err]} {
+		error_popup [strcat [mc "Unable to unlock the index."] "\n\n$err"]
+	}
+}
+
+proc _close_updateindex {fd after} {
+	fconfigure $fd -blocking 1
+	if {[catch {close $fd} err]} {
+		set w .indexfried
+		toplevel $w
+		wm title $w [strcat "[appname] ([reponame]): " [mc "Index Error"]]
+		wm geometry $w "+[winfo rootx .]+[winfo rooty .]"
+		pack [label $w.msg \
+			-justify left \
+			-anchor w \
+			-text [strcat \
+				[mc "Updating the Git index failed.  A rescan will be automatically started to resynchronize git-gui."] \
+				"\n\n$err"] \
+			] -anchor w
+
+		frame $w.buttons
+		button $w.buttons.continue \
+			-text [mc "Continue"] \
+			-command [list destroy $w]
+		pack $w.buttons.continue -side right -padx 5
+		button $w.buttons.unlock \
+			-text [mc "Unlock Index"] \
+			-command "destroy $w; _delete_indexlock"
+		pack $w.buttons.unlock -side right
+		pack $w.buttons -side bottom -fill x -pady 10 -padx 10
+
+		wm protocol $w WM_DELETE_WINDOW update
+		bind $w.buttons.continue <Visibility> "
+			grab $w
+			focus $w.buttons.continue
+		"
+		tkwait window $w
+
+		$::main_status stop
+		unlock_index
+		rescan $after 0
+		return
+	}
+
+	unlock_index
+	uplevel #0 $after
+}
+
 proc update_indexinfo {msg pathList after} {
 	global update_index_cp
 
 	global file_states current_diff_path
 
 	if {$update_index_cp >= $totalCnt} {
-		close $fd
-		unlock_index
-		uplevel #0 $after
+		_close_updateindex $fd $after
 		return
 	}
 
 	global file_states current_diff_path
 
 	if {$update_index_cp >= $totalCnt} {
-		close $fd
-		unlock_index
-		uplevel #0 $after
+		_close_updateindex $fd $after
 		return
 	}
 
 	global file_states current_diff_path
 
 	if {$update_index_cp >= $totalCnt} {
-		close $fd
-		unlock_index
-		uplevel #0 $after
+		_close_updateindex $fd $after
 		return
 	}
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.