Permalink
Browse files

add tests for git patching

  • Loading branch information...
1 parent a3c5139 commit 6ce0e43003517c1954fd4e238f9c15f945c6a3d6 @technoweenie technoweenie committed Jan 13, 2011
@@ -0,0 +1 @@
+good patch
View
@@ -0,0 +1 @@
+ref: refs/heads/master
View
@@ -0,0 +1,6 @@
+[core]
+ repositoryformatversion = 0
+ filemode = true
+ bare = false
+ logallrefupdates = true
+ ignorecase = true
View
@@ -0,0 +1 @@
+Unnamed repository; edit this file 'description' to name the repository.
View
Binary file not shown.
View
@@ -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]
+# *~
View
@@ -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
@@ -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
@@ -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
@@ -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.
@@ -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.
@@ -0,0 +1 @@
+f252f9a68245f465d27b31fcdbf63ab55de58b06
@@ -0,0 +1 @@
+f3c031e78b368d1b9b03c3eb1b90d8a122277e67
@@ -0,0 +1 @@
+cf75ecfce82fb2a8723f86b140980994f0065ecd
View
@@ -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"))
View
@@ -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.