-
Notifications
You must be signed in to change notification settings - Fork 283
/
Copy pathrepo_reset_test.rb
85 lines (64 loc) · 2.44 KB
/
repo_reset_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
require "test_helper"
class RepositoryResetTest < Rugged::TestCase
def setup
@source_repo = FixtureRepo.from_rugged("testrepo.git")
@repo = FixtureRepo.clone(@source_repo)
end
def repo_file_path; File.join('subdir', 'README') end
def file_path; File.join(@repo.workdir, 'subdir', 'README') end
def test_reset_with_rugged_tag
tag = @repo.lookup('0c37a5391bbff43c37f0d0371823a5509eed5b1d')
@repo.reset(tag, :soft)
assert_equal tag.target_id , @repo.head.target_id
end
def test_reset_with_invalid_mode
assert_raises ArgumentError do
@repo.reset('441034f860c1d5d90e4188d11ae0d325176869a8', :tender)
end
end
def test_reset_soft
original_content = File.open(file_path) { |f| f.read }
@repo.reset('441034f860c1d5d90e4188d11ae0d325176869a8', :soft)
assert_equal '441034f860c1d5d90e4188d11ae0d325176869a8', @repo.head.target_id
assert_equal [:index_modified], @repo.status(repo_file_path)
new_content = File.open(file_path) { |f| f.read }
assert_equal original_content, new_content
end
def test_reset_mixed
original_content = File.open(file_path) { |f| f.read }
@repo.reset('441034f860c1d5d90e4188d11ae0d325176869a8', :mixed)
assert_equal [:worktree_modified], @repo.status(repo_file_path)
new_content = File.open(file_path) { |f| f.read }
assert_equal original_content, new_content
end
def test_reset_hard
original_content = File.open(file_path) { |f| f.read }
@repo.reset('441034f860c1d5d90e4188d11ae0d325176869a8', :hard)
assert_empty @repo.status(repo_file_path)
new_content = File.open(file_path) { |f| f.read }
refute_equal original_content, new_content
end
def test_reset_path
File.open(file_path, 'w') do |f|
f.puts "test content"
end
@repo.index.add(repo_file_path)
@repo.index.write
@repo.reset_path(repo_file_path, '441034f860c1d5d90e4188d11ae0d325176869a8')
assert_equal [:index_modified, :worktree_modified], @repo.status(repo_file_path)
end
def test_reset_path_no_target
File.open(file_path, 'w') do |f|
f.puts "test content"
end
@repo.index.add(repo_file_path)
@repo.index.write
@repo.reset_path(repo_file_path)
assert_equal [:index_deleted, :worktree_new], @repo.status(repo_file_path)
end
def test_reset_path_invalid_pathspec
assert_raises TypeError do
@repo.reset_path([:invalid_reset_path], '441034f860c1d5d90e4188d11ae0d325176869a8')
end
end
end