Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add tests for git patching

  • Loading branch information...
commit 6ce0e43003517c1954fd4e238f9c15f945c6a3d6 1 parent a3c5139
@technoweenie technoweenie authored
Showing with 74 additions and 1 deletion.
  1. +1 −0  test/patch/COMMIT_EDITMSG
  2. +1 −0  test/patch/HEAD
  3. +6 −0 test/patch/config
  4. +1 −0  test/patch/description
  5. BIN  test/patch/index
  6. +6 −0 test/patch/info/exclude
  7. +8 −0 test/patch/logs/HEAD
  8. +2 −0  test/patch/logs/refs/heads/bad
  9. +2 −0  test/patch/logs/refs/heads/good
  10. +2 −0  test/patch/logs/refs/heads/master
  11. BIN  test/patch/objects/0d/59bef5ff65a0f09ae0259a4f20625ff9d9d64b
  12. +2 −0  test/patch/objects/5d/a862ffd84e42b687b65605788f4158f4610400
  13. BIN  test/patch/objects/6f/3cad7a2f103336238fa22cc6d947525b16dfa8
  14. BIN  test/patch/objects/72/56d4ce5aa848032fc1e23d6b3254296de9e529
  15. BIN  test/patch/objects/89/3adcd31e963b01dfbbcfe3ec58a008f0d81201
  16. BIN  test/patch/objects/c3/1db71f041e94f88e44b72f2634a810d4ec61c2
  17. BIN  test/patch/objects/cf/75ecfce82fb2a8723f86b140980994f0065ecd
  18. BIN  test/patch/objects/e7/9c5e8f964493290a409888d5413a737e8e5dd5
  19. BIN  test/patch/objects/f2/52f9a68245f465d27b31fcdbf63ab55de58b06
  20. BIN  test/patch/objects/f3/c031e78b368d1b9b03c3eb1b90d8a122277e67
  21. +1 −0  test/patch/refs/heads/bad
  22. +1 −0  test/patch/refs/heads/good
  23. +1 −0  test/patch/refs/heads/master
  24. +1 −1  test/test_git.rb
  25. +39 −0 test/test_git_patching.rb
View
1  test/patch/COMMIT_EDITMSG
@@ -0,0 +1 @@
+good patch
View
1  test/patch/HEAD
@@ -0,0 +1 @@
+ref: refs/heads/master
View
6 test/patch/config
@@ -0,0 +1,6 @@
+[core]
+ repositoryformatversion = 0
+ filemode = true
+ bare = false
+ logallrefupdates = true
+ ignorecase = true
View
1  test/patch/description
@@ -0,0 +1 @@
+Unnamed repository; edit this file 'description' to name the repository.
View
BIN  test/patch/index
Binary file not shown
View
6 test/patch/info/exclude
@@ -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
8 test/patch/logs/HEAD
@@ -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
View
2  test/patch/logs/refs/heads/bad
@@ -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
View
2  test/patch/logs/refs/heads/good
@@ -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
View
2  test/patch/logs/refs/heads/master
@@ -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
View
BIN  test/patch/objects/0d/59bef5ff65a0f09ae0259a4f20625ff9d9d64b
Binary file not shown
View
2  test/patch/objects/5d/a862ffd84e42b687b65605788f4158f4610400
@@ -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�
View
BIN  test/patch/objects/6f/3cad7a2f103336238fa22cc6d947525b16dfa8
Binary file not shown
View
BIN  test/patch/objects/72/56d4ce5aa848032fc1e23d6b3254296de9e529
Binary file not shown
View
BIN  test/patch/objects/89/3adcd31e963b01dfbbcfe3ec58a008f0d81201
Binary file not shown
View
BIN  test/patch/objects/c3/1db71f041e94f88e44b72f2634a810d4ec61c2
Binary file not shown
View
BIN  test/patch/objects/cf/75ecfce82fb2a8723f86b140980994f0065ecd
Binary file not shown
View
BIN  test/patch/objects/e7/9c5e8f964493290a409888d5413a737e8e5dd5
Binary file not shown
View
BIN  test/patch/objects/f2/52f9a68245f465d27b31fcdbf63ab55de58b06
Binary file not shown
View
BIN  test/patch/objects/f3/c031e78b368d1b9b03c3eb1b90d8a122277e67
Binary file not shown
View
1  test/patch/refs/heads/bad
@@ -0,0 +1 @@
+f252f9a68245f465d27b31fcdbf63ab55de58b06
View
1  test/patch/refs/heads/good
@@ -0,0 +1 @@
+f3c031e78b368d1b9b03c3eb1b90d8a122277e67
View
1  test/patch/refs/heads/master
@@ -0,0 +1 @@
+cf75ecfce82fb2a8723f86b140980994f0065ecd
View
2  test/test_git.rb
@@ -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
39 test/test_git_patching.rb
@@ -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.
Something went wrong with that request. Please try again.