File tree Expand file tree Collapse file tree 1 file changed +19
-5
lines changed
Expand file tree Collapse file tree 1 file changed +19
-5
lines changed Original file line number Diff line number Diff line change @@ -223,17 +223,31 @@ impl Repository {
223223}
224224
225225fn check_git_repository ( path : & Path ) -> Result < ( ) > {
226+ if !is_inside_work_tree ( path) && !is_bare_repository ( path) {
227+ let msg = "not a git repository (or any of the parent directories)" ;
228+ return Err ( msg. into ( ) ) ;
229+ }
230+ Ok ( ( ) )
231+ }
232+
233+ fn is_inside_work_tree ( path : & Path ) -> bool {
226234 let output = Command :: new ( "git" )
227235 . arg ( "rev-parse" )
228236 . arg ( "--is-inside-work-tree" )
229237 . current_dir ( path)
230238 . output ( )
231239 . unwrap ( ) ;
232- if !output. status . success ( ) || output. stdout == b"false\n " {
233- let msg = "not a git repository (or any of the parent directories)" ;
234- return Err ( msg. into ( ) ) ;
235- }
236- Ok ( ( ) )
240+ output. status . success ( ) && output. stdout == b"true\n "
241+ }
242+
243+ fn is_bare_repository ( path : & Path ) -> bool {
244+ let output = Command :: new ( "git" )
245+ . arg ( "rev-parse" )
246+ . arg ( "--is-bare-repository" )
247+ . current_dir ( path)
248+ . output ( )
249+ . unwrap ( ) ;
250+ output. status . success ( ) && output. stdout == b"true\n "
237251}
238252
239253fn load_all_commits ( path : & Path , sort : SortCommit , stashes : & [ Commit ] ) -> Vec < Commit > {
You can’t perform that action at this time.
0 commit comments