Commits

Anonymous committed a13ee29

git-gui: Avoid Tcl error in popup menu on diff viewer

If there is no path currently shown in the diff viewer then we
were getting Tcl errors anytime the user right-clicked on the
diff viewer to bring up its popup menu. The bug here is caused
by trying to get the file_state for the empty string; this path
is never seen so we never have file_state for it. In such cases
we now disable the Stage Hunk For Commit option.

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

Comments (0)

Files changed (1)

 $ctxm add command -label {Options...} \
 	-command do_options
 proc popup_diff_menu {ctxm x y X Y} {
+	global current_diff_path
 	set ::cursorX $x
 	set ::cursorY $y
 	if {$::ui_index eq $::current_diff_side} {
 		$ctxm entryconf $::ui_diff_applyhunk \
 			-state normal \
 			-label {Unstage Hunk From Commit}
-	} elseif {{_O} eq [lindex $::file_states($::current_diff_path) 0]} {
+	} elseif {![info exists file_states($current_diff_path)]
+		|| {_O} eq [lindex $file_states($::current_diff_path) 0]} {
 		$ctxm entryconf $::ui_diff_applyhunk \
 			-state disabled \
 			-label {Stage Hunk For Commit}
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.