git-gui: Allow blame/browser subcommands on bare repositories
A long time ago Linus Torvalds tried to run git-gui on a bare repository to look at the blame viewer, but it failed to start because we required that the user run us only from within a working directory that had a normal git repository associated with it. This change relaxes that requirement so that you can start the tree browser or the blame viewer against a bare repository. In the latter case we do require that you provide a revision and a pathname if we cannot find the pathname in the current working directory. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Shawn O. Pearce committed
Jul 17, 2007 at 23:58 UTC
c52c94524bdf9bbe515137b7f3f0240bc10a7f63
1 file changed
+32
-13
git-gui.sh
+32
-13
@@ -650,10 +650,13 @@ if {$subcommand eq {gui} && [llength $argv] > 0} {
650
enable_option multicommit
651
enable_option branch
652
enable_option transport
653
+disable_option bare
654
655
switch -- $subcommand {
656
browser -
657
blame {
658
+ enable_option bare
659
+
660
disable_option multicommit
661
disable_option branch
662
disable_option transport
@@ -691,19 +694,24 @@ if {![file isdirectory $_gitdir]} {
694
error_popup "Git directory not found:\n\n$_gitdir"
695
exit 1
696
}
694
-if {[lindex [file split $_gitdir] end] ne {.git}} {
695
- catch {wm withdraw .}
696
- error_popup "Cannot use funny .git directory:\n\n$_gitdir"
697
- exit 1
697
+if {![is_enabled bare]} {
698
+ if {[lindex [file split $_gitdir] end] ne {.git}} {
699
+ catch {wm withdraw .}
700
+ error_popup "Cannot use funny .git directory:\n\n$_gitdir"
701
+ exit 1
702
+ }
703
+ if {[catch {cd [file dirname $_gitdir]} err]} {
704
+ catch {wm withdraw .}
705
+ error_popup "No working directory [file dirname $_gitdir]:\n\n$err"
706
+ exit 1
707
+ }
708
}
699
-if {[catch {cd [file dirname $_gitdir]} err]} {
700
- catch {wm withdraw .}
701
- error_popup "No working directory [file dirname $_gitdir]:\n\n$err"
702
- exit 1
709
+set _reponame [file split [file normalize $_gitdir]]
710
+if {[lindex $_reponame end] eq {.git}} {
711
+ set _reponame [lindex $_reponame end-1]
712
+} else {
713
+ set _reponame [lindex $_reponame end]
714
}
704
-set _reponame [lindex [file split \
705
- [file normalize [file dirname $_gitdir]]] \
706
- end]
715
716
######################################################################
717
##
@@ -1990,7 +1998,8 @@ browser {
1998
return
1999
}
2000
blame {
1993
- set subcommand_args {rev? path?}
2001
+ set subcommand_args {rev? path}
2002
+ if {$argv eq {}} usage
2003
set head {}
2004
set path {}
2005
set is_path 0
@@ -2009,12 +2018,18 @@ blame {
2018
} elseif {$head eq {}} {
2019
if {$head ne {}} usage
2020
set head $a
2021
+ set is_path 1
2022
} else {
2023
usage
2024
}
2025
}
2026
unset is_path
2027
2028
+ if {$head ne {} && $path eq {}} {
2029
+ set path $_prefix$head
2030
+ set head {}
2031
+ }
2032
+
2033
if {$head eq {}} {
2034
load_current_branch
2035
} else {
@@ -2029,7 +2044,11 @@ blame {
2044
set current_branch $head
2045
}
2046
2032
- if {$path eq {}} usage
2047
+ if {$head eq {} && ![file exists $path]} {
2048
+ puts stderr "fatal: cannot stat path $path: No such file or directory"
2049
+ exit 1
2050
+ }
2051
+
2052
blame::new $head $path
2053
return
2054
}