File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -793,6 +793,16 @@ def gc
793
793
command ( 'gc' , [ '--prune' , '--aggressive' , '--auto' ] )
794
794
end
795
795
796
+ def fsck
797
+ begin
798
+ command ( 'fsck' )
799
+ rescue
800
+ return false
801
+ end
802
+
803
+ true
804
+ end
805
+
796
806
# reads a tree into the current index file
797
807
def read_tree ( treeish , opts = { } )
798
808
arr_opts = [ ]
Original file line number Diff line number Diff line change @@ -228,4 +228,25 @@ def test_show
228
228
assert ( /^hello.+nothing!$/m . match ( @lib . show ( 'gitsearch1' , 'scott/text.txt' ) ) )
229
229
end
230
230
231
+ def test_fsck
232
+ ret = @lib . fsck
233
+ assert_equal ( ret , true )
234
+
235
+ # Corrupted
236
+ @wdir_corrupted = File . expand_path ( File . join ( @test_dir , 'corrupted' ) )
237
+ FileUtils . cp_r ( @wdir , @wdir_corrupted )
238
+ # Remove first objects dir to corrupt the repo
239
+ obj_dir = File . join ( @wdir_corrupted , '.git' , 'objects' )
240
+ Dir . foreach ( obj_dir ) do |filename |
241
+ next if filename == '.'
242
+ next if filename == '..'
243
+ FileUtils . rm_r ( File . join ( obj_dir , filename ) )
244
+ break
245
+ end
246
+
247
+ lib_corrupted = Git . open ( @wdir_corrupted ) . lib
248
+ ret = lib_corrupted . fsck
249
+ assert_equal ( ret , false )
250
+ end
251
+
231
252
end
You can’t perform that action at this time.
0 commit comments