Skip to content

Commit

Permalink
add tests for git patching
Browse files Browse the repository at this point in the history
  • Loading branch information
technoweenie committed Jan 13, 2011
1 parent a3c5139 commit 6ce0e43
Show file tree
Hide file tree
Showing 25 changed files with 74 additions and 1 deletion.
1 change: 1 addition & 0 deletions test/patch/COMMIT_EDITMSG
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
good patch
1 change: 1 addition & 0 deletions test/patch/HEAD
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ref: refs/heads/master
6 changes: 6 additions & 0 deletions test/patch/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
1 change: 1 addition & 0 deletions test/patch/description
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Unnamed repository; edit this file 'description' to name the repository.
Binary file added test/patch/index
Binary file not shown.
6 changes: 6 additions & 0 deletions test/patch/info/exclude
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# git ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
# *.[oa]
# *~
8 changes: 8 additions & 0 deletions test/patch/logs/HEAD
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
0000000000000000000000000000000000000000 5da862ffd84e42b687b65605788f4158f4610400 rick <technoweenie@gmail.com> 1294902968 -0800 commit (initial): initial
5da862ffd84e42b687b65605788f4158f4610400 5da862ffd84e42b687b65605788f4158f4610400 rick <technoweenie@gmail.com> 1294902973 -0800 checkout: moving from master to bad
5da862ffd84e42b687b65605788f4158f4610400 f252f9a68245f465d27b31fcdbf63ab55de58b06 rick <technoweenie@gmail.com> 1294902998 -0800 commit: bad patch
f252f9a68245f465d27b31fcdbf63ab55de58b06 5da862ffd84e42b687b65605788f4158f4610400 rick <technoweenie@gmail.com> 1294902999 -0800 checkout: moving from bad to master
5da862ffd84e42b687b65605788f4158f4610400 cf75ecfce82fb2a8723f86b140980994f0065ecd rick <technoweenie@gmail.com> 1294903011 -0800 commit: update
cf75ecfce82fb2a8723f86b140980994f0065ecd cf75ecfce82fb2a8723f86b140980994f0065ecd rick <technoweenie@gmail.com> 1294903013 -0800 checkout: moving from master to good
cf75ecfce82fb2a8723f86b140980994f0065ecd f3c031e78b368d1b9b03c3eb1b90d8a122277e67 rick <technoweenie@gmail.com> 1294903038 -0800 commit: good patch
f3c031e78b368d1b9b03c3eb1b90d8a122277e67 cf75ecfce82fb2a8723f86b140980994f0065ecd rick <technoweenie@gmail.com> 1294903041 -0800 checkout: moving from good to master
2 changes: 2 additions & 0 deletions test/patch/logs/refs/heads/bad
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
0000000000000000000000000000000000000000 5da862ffd84e42b687b65605788f4158f4610400 rick <technoweenie@gmail.com> 1294902973 -0800 branch: Created from HEAD
5da862ffd84e42b687b65605788f4158f4610400 f252f9a68245f465d27b31fcdbf63ab55de58b06 rick <technoweenie@gmail.com> 1294902998 -0800 commit: bad patch
2 changes: 2 additions & 0 deletions test/patch/logs/refs/heads/good
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
0000000000000000000000000000000000000000 cf75ecfce82fb2a8723f86b140980994f0065ecd rick <technoweenie@gmail.com> 1294903013 -0800 branch: Created from HEAD
cf75ecfce82fb2a8723f86b140980994f0065ecd f3c031e78b368d1b9b03c3eb1b90d8a122277e67 rick <technoweenie@gmail.com> 1294903038 -0800 commit: good patch
2 changes: 2 additions & 0 deletions test/patch/logs/refs/heads/master
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
0000000000000000000000000000000000000000 5da862ffd84e42b687b65605788f4158f4610400 rick <technoweenie@gmail.com> 1294902968 -0800 commit (initial): initial
5da862ffd84e42b687b65605788f4158f4610400 cf75ecfce82fb2a8723f86b140980994f0065ecd rick <technoweenie@gmail.com> 1294903011 -0800 commit: update
Binary file not shown.
2 changes: 2 additions & 0 deletions test/patch/objects/5d/a862ffd84e42b687b65605788f4158f4610400
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
x��]
B!@�]�l���'�K�ө;tU����[����)�50!�d�}����9��->�!�5<,z�)TJ�1���}L�\ް ���/Qg��Z��RF����^*�YG�ժk'�7T�Y8�̓5�
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions test/patch/refs/heads/bad
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
f252f9a68245f465d27b31fcdbf63ab55de58b06
1 change: 1 addition & 0 deletions test/patch/refs/heads/good
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
f3c031e78b368d1b9b03c3eb1b90d8a122277e67
1 change: 1 addition & 0 deletions test/patch/refs/heads/master
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cf75ecfce82fb2a8723f86b140980994f0065ecd
2 changes: 1 addition & 1 deletion test/test_git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def test_logs_stderr
@git.bad
end

def testl_logs_stderr_when_skipping_timeout
def test_logs_stderr_when_skipping_timeout
Grit.debug = true
Grit.stubs(:log)
Grit.expects(:log).with(includes("git: 'bad' is not a git command"))
Expand Down
39 changes: 39 additions & 0 deletions test/test_git_patching.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
require File.dirname(__FILE__) + '/helper'

class TestGitPatching < Test::Unit::TestCase
def setup
@testdir = File.dirname(__FILE__)
@patchdir = File.join(@testdir, 'patch')
@clonedir = File.join(@testdir, 'patch_clone.git')
@git = Git.new(@patchdir)
end

def teardown
Grit.debug = false
FileUtils.rm_rf(@clonedir)
end

def test_gets_a_valid_patch
assert_match /\-patchme/, @git.get_patch("good")
assert_match /\-initial/, @git.get_patch("bad")
end

def test_checks_patch_applies
assert_equal 0, @git.check_applies("master", "good")
assert_equal 1, @git.check_applies("master", "bad")
end

def test_applies_patch
repo = Grit::Repo.new(@patchdir, :is_bare => true)
clone = repo.fork_bare(@clonedir)
assert_equal 'patchme', (clone.tree / 'patchme').data.strip

badpatch = clone.git.get_patch('bad')
assert !clone.git.apply_patch('master', badpatch)
assert_equal 'patchme', (clone.tree / 'patchme').data.strip

goodpatch = clone.git.get_patch('good')
sha = clone.git.apply_patch('master', goodpatch)
assert_equal 'patched', (clone.tree(sha) / 'patchme').data.strip
end
end

0 comments on commit 6ce0e43

Please sign in to comment.