Skip to content
This repository
Browse code

Add some tests for doing a workdir diff.

  • Loading branch information...
commit b93769f8b4d40c1d579bff21e05b7136af7f6a47 1 parent 32091e8
Arthur Schreiber authored May 25, 2013

Showing 51 changed files with 85 additions and 0 deletions. Show diff stats Hide diff stats

  1. 35  test/diff_test.rb
  2. 1  test/fixtures/status/.gitted/COMMIT_EDITMSG
  3. 1  test/fixtures/status/.gitted/HEAD
  4. 1  test/fixtures/status/.gitted/ORIG_HEAD
  5. 6  test/fixtures/status/.gitted/config
  6. 1  test/fixtures/status/.gitted/description
  7. BIN  test/fixtures/status/.gitted/index
  8. 8  test/fixtures/status/.gitted/info/exclude
  9. 3  test/fixtures/status/.gitted/logs/HEAD
  10. 3  test/fixtures/status/.gitted/logs/refs/heads/master
  11. 2  test/fixtures/status/.gitted/objects/00/17bd4ab1ec30440b17bae1680cff124ab5f1f6
  12. BIN  test/fixtures/status/.gitted/objects/06/1d42a44cacde5726057b67558821d95db96f19
  13. BIN  test/fixtures/status/.gitted/objects/18/88c805345ba265b0ee9449b8877b6064592058
  14. BIN  test/fixtures/status/.gitted/objects/19/d9cc8584ac2c7dcf57d2680375e80f099dc481
  15. 2  test/fixtures/status/.gitted/objects/26/a125ee1bfc5df1e1b2e9441bbe63c8a7ae989f
  16. BIN  test/fixtures/status/.gitted/objects/32/504b727382542f9f089e24fddac5e78533e96c
  17. BIN  test/fixtures/status/.gitted/objects/37/fcb02ccc1a85d1941e7f106d52dc3702dcf0d0
  18. BIN  test/fixtures/status/.gitted/objects/45/2e4244b5d083ddf0460acf1ecc74db9dcfa11a
  19. BIN  test/fixtures/status/.gitted/objects/52/9a16e8e762d4acb7b9636ff540a00831f9155a
  20. BIN  test/fixtures/status/.gitted/objects/53/ace0d1cc1145a5f4fe4f78a186a60263190733
  21. BIN  test/fixtures/status/.gitted/objects/54/52d32f1dd538eb0405e8a83cc185f79e25e80f
  22. BIN  test/fixtures/status/.gitted/objects/55/d316c9ba708999f1918e9677d01dfcae69c6b9
  23. BIN  test/fixtures/status/.gitted/objects/70/bd9443ada07063e7fbf0b3ff5c13f7494d89c2
  24. BIN  test/fixtures/status/.gitted/objects/73/5b6a258cd196a8f7c9428419b02c1dca93fd75
  25. BIN  test/fixtures/status/.gitted/objects/75/6e27627e67bfbc048d01ece5819c6de733d7ea
  26. BIN  test/fixtures/status/.gitted/objects/90/6ee7711f4f4928ddcb2a5f8fbc500deba0d2a8
  27. BIN  test/fixtures/status/.gitted/objects/90/b8c29d8ba39434d1c63e1b093daaa26e5bd972
  28. BIN  test/fixtures/status/.gitted/objects/9c/2e02cdffa8d73e6c189074594477a6baf87960
  29. BIN  test/fixtures/status/.gitted/objects/a0/de7e0ac200c489c41c59dfa910154a70264e6e
  30. BIN  test/fixtures/status/.gitted/objects/a6/191982709b746d5650e93c2acf34ef74e11504
  31. BIN  test/fixtures/status/.gitted/objects/a6/be623522ce87a1d862128ac42672604f7b468b
  32. BIN  test/fixtures/status/.gitted/objects/aa/27a641456848200fdb7f7c99ba36f8a0952877
  33. BIN  test/fixtures/status/.gitted/objects/da/bc8af9bd6e9f5bbe96a176f1a24baf3d1f8916
  34. BIN  test/fixtures/status/.gitted/objects/e8/ee89e15bbe9b20137715232387b3de5b28972e
  35. BIN  test/fixtures/status/.gitted/objects/e9/b9107f290627c04d097733a10055af941f6bca
  36. BIN  test/fixtures/status/.gitted/objects/ed/062903b8f6f3dccb2fa81117ba6590944ef9bd
  37. 1  test/fixtures/status/.gitted/refs/heads/master
  38. 1  test/fixtures/status/current_file
  39. 1  test/fixtures/status/ignored_file
  40. 2  test/fixtures/status/modified_file
  41. 1  test/fixtures/status/new_file
  42. 2  test/fixtures/status/staged_changes
  43. 3  test/fixtures/status/staged_changes_modified_file
  44. 1  test/fixtures/status/staged_delete_modified_file
  45. 1  test/fixtures/status/staged_new_file
  46. 2  test/fixtures/status/staged_new_file_modified_file
  47. 2  test/fixtures/status/subdir.txt
  48. 1  test/fixtures/status/subdir/current_file
  49. 2  test/fixtures/status/subdir/modified_file
  50. 1  test/fixtures/status/subdir/new_file
  51. 1  test/fixtures/status/这
35  test/diff_test.rb
@@ -133,6 +133,41 @@ def test_diff_with_parent_for_initial_commit
133 133
   end
134 134
 end
135 135
 
  136
+class TreeToWorkdirTest < Rugged::SandboxedTestCase
  137
+  def test_basic_diff
  138
+    repo = sandbox_init("status")
  139
+    a = Rugged::Tree.lookup(repo, "26a125ee1bf").tree
  140
+
  141
+    diff = a.diff_workdir(
  142
+      :context_lines => 3,
  143
+      :interhunk_lines => 1,
  144
+      :include_ignored => true,
  145
+      :include_untracked => true
  146
+    )
  147
+
  148
+    deltas = diff.deltas
  149
+    patches = diff.patches
  150
+    hunks = patches.map(&:hunks).flatten
  151
+    lines = hunks.map(&:lines).flatten
  152
+
  153
+    assert_equal 14, deltas.size
  154
+    assert_equal 14, patches.size
  155
+
  156
+    assert_equal 0, deltas.select(&:added?).size
  157
+    assert_equal 4, deltas.select(&:deleted?).size
  158
+    assert_equal 4, deltas.select(&:modified?).size
  159
+    assert_equal 1, deltas.select(&:ignored?).size
  160
+    assert_equal 5, deltas.select(&:untracked?).size
  161
+
  162
+    assert_equal 8, hunks.size
  163
+
  164
+    assert_equal 13, lines.size
  165
+    assert_equal 4, lines.select(&:context?).size
  166
+    assert_equal 5, lines.select(&:addition?).size
  167
+    assert_equal 4, lines.select(&:deletion?).size
  168
+  end
  169
+end
  170
+
136 171
 class TreeToTreeDiffTest < Rugged::SandboxedTestCase
137 172
   def test_basic_diff
138 173
     repo = sandbox_init("attr")
1  test/fixtures/status/.gitted/COMMIT_EDITMSG
... ...
@@ -0,0 +1 @@
  1
+Add a file which name should appear before the "subdir/" folder while being dealt with by the treewalker
1  test/fixtures/status/.gitted/HEAD
... ...
@@ -0,0 +1 @@
  1
+ref: refs/heads/master
1  test/fixtures/status/.gitted/ORIG_HEAD
... ...
@@ -0,0 +1 @@
  1
+735b6a258cd196a8f7c9428419b02c1dca93fd75
6  test/fixtures/status/.gitted/config
... ...
@@ -0,0 +1,6 @@
  1
+[core]
  2
+	repositoryformatversion = 0
  3
+	filemode = true
  4
+	bare = false
  5
+	logallrefupdates = true
  6
+	ignorecase = true
1  test/fixtures/status/.gitted/description
... ...
@@ -0,0 +1 @@
  1
+Unnamed repository; edit this file 'description' to name the repository.
BIN  test/fixtures/status/.gitted/index
Binary file not shown
8  test/fixtures/status/.gitted/info/exclude
... ...
@@ -0,0 +1,8 @@
  1
+# git ls-files --others --exclude-from=.git/info/exclude
  2
+# Lines that start with '#' are comments.
  3
+# For a project mostly in C, the following would be a good set of
  4
+# exclude patterns (uncomment them if you want to use them):
  5
+# *.[oa]
  6
+# *~
  7
+ignored*
  8
+
3  test/fixtures/status/.gitted/logs/HEAD
... ...
@@ -0,0 +1,3 @@
  1
+0000000000000000000000000000000000000000 0017bd4ab1ec30440b17bae1680cff124ab5f1f6 Jason Penny <jasonpenny4@gmail.com> 1308050070 -0400	commit (initial): initial
  2
+0017bd4ab1ec30440b17bae1680cff124ab5f1f6 735b6a258cd196a8f7c9428419b02c1dca93fd75 Jason Penny <jasonpenny4@gmail.com> 1308954538 -0400	commit: add subdir
  3
+735b6a258cd196a8f7c9428419b02c1dca93fd75 26a125ee1bfc5df1e1b2e9441bbe63c8a7ae989f nulltoken <emeric.fermas@gmail.com> 1319911544 +0200	commit: Add a file which name should appear before the "subdir/" folder while being dealt with by the treewalker
3  test/fixtures/status/.gitted/logs/refs/heads/master
... ...
@@ -0,0 +1,3 @@
  1
+0000000000000000000000000000000000000000 0017bd4ab1ec30440b17bae1680cff124ab5f1f6 Jason Penny <jasonpenny4@gmail.com> 1308050070 -0400	commit (initial): initial
  2
+0017bd4ab1ec30440b17bae1680cff124ab5f1f6 735b6a258cd196a8f7c9428419b02c1dca93fd75 Jason Penny <jasonpenny4@gmail.com> 1308954538 -0400	commit: add subdir
  3
+735b6a258cd196a8f7c9428419b02c1dca93fd75 26a125ee1bfc5df1e1b2e9441bbe63c8a7ae989f nulltoken <emeric.fermas@gmail.com> 1319911544 +0200	commit: Add a file which name should appear before the "subdir/" folder while being dealt with by the treewalker
2  test/fixtures/status/.gitted/objects/00/17bd4ab1ec30440b17bae1680cff124ab5f1f6
... ...
@@ -0,0 +1,2 @@
  1
+xA E]sfh)1]
  2
+#STWpK^~9ܡ-"C'؅)Fvbv"wEk{nRί6#sOpD663WxV?9
BIN  test/fixtures/status/.gitted/objects/06/1d42a44cacde5726057b67558821d95db96f19
Binary file not shown
BIN  test/fixtures/status/.gitted/objects/18/88c805345ba265b0ee9449b8877b6064592058
Binary file not shown
BIN  test/fixtures/status/.gitted/objects/19/d9cc8584ac2c7dcf57d2680375e80f099dc481
Binary file not shown
2  test/fixtures/status/.gitted/objects/26/a125ee1bfc5df1e1b2e9441bbe63c8a7ae989f
... ...
@@ -0,0 +1,2 @@
  1
+xMn )V (̀BD޾LЍRȷވ@,9̜tNj6f`M6Z;h
Zp	ڙY,37/;42x&<z
#^
  2
+䮁ZQ0嫫pޙ`l?{@)1+=#ö6j#֧qP>gϟۉIm|j
BIN  test/fixtures/status/.gitted/objects/32/504b727382542f9f089e24fddac5e78533e96c
Binary file not shown
BIN  test/fixtures/status/.gitted/objects/37/fcb02ccc1a85d1941e7f106d52dc3702dcf0d0
Binary file not shown
BIN  test/fixtures/status/.gitted/objects/45/2e4244b5d083ddf0460acf1ecc74db9dcfa11a
Binary file not shown
BIN  test/fixtures/status/.gitted/objects/52/9a16e8e762d4acb7b9636ff540a00831f9155a
Binary file not shown
BIN  test/fixtures/status/.gitted/objects/53/ace0d1cc1145a5f4fe4f78a186a60263190733
Binary file not shown
BIN  test/fixtures/status/.gitted/objects/54/52d32f1dd538eb0405e8a83cc185f79e25e80f
Binary file not shown
BIN  test/fixtures/status/.gitted/objects/55/d316c9ba708999f1918e9677d01dfcae69c6b9
Binary file not shown
BIN  test/fixtures/status/.gitted/objects/70/bd9443ada07063e7fbf0b3ff5c13f7494d89c2
Binary file not shown
BIN  test/fixtures/status/.gitted/objects/73/5b6a258cd196a8f7c9428419b02c1dca93fd75
Binary file not shown
BIN  test/fixtures/status/.gitted/objects/75/6e27627e67bfbc048d01ece5819c6de733d7ea
Binary file not shown
BIN  test/fixtures/status/.gitted/objects/90/6ee7711f4f4928ddcb2a5f8fbc500deba0d2a8
Binary file not shown
BIN  test/fixtures/status/.gitted/objects/90/b8c29d8ba39434d1c63e1b093daaa26e5bd972
Binary file not shown
BIN  test/fixtures/status/.gitted/objects/9c/2e02cdffa8d73e6c189074594477a6baf87960
Binary file not shown
BIN  test/fixtures/status/.gitted/objects/a0/de7e0ac200c489c41c59dfa910154a70264e6e
Binary file not shown
BIN  test/fixtures/status/.gitted/objects/a6/191982709b746d5650e93c2acf34ef74e11504
Binary file not shown
BIN  test/fixtures/status/.gitted/objects/a6/be623522ce87a1d862128ac42672604f7b468b
Binary file not shown
BIN  test/fixtures/status/.gitted/objects/aa/27a641456848200fdb7f7c99ba36f8a0952877
Binary file not shown
BIN  test/fixtures/status/.gitted/objects/da/bc8af9bd6e9f5bbe96a176f1a24baf3d1f8916
Binary file not shown
BIN  test/fixtures/status/.gitted/objects/e8/ee89e15bbe9b20137715232387b3de5b28972e
Binary file not shown
BIN  test/fixtures/status/.gitted/objects/e9/b9107f290627c04d097733a10055af941f6bca
Binary file not shown
BIN  test/fixtures/status/.gitted/objects/ed/062903b8f6f3dccb2fa81117ba6590944ef9bd
Binary file not shown
1  test/fixtures/status/.gitted/refs/heads/master
... ...
@@ -0,0 +1 @@
  1
+26a125ee1bfc5df1e1b2e9441bbe63c8a7ae989f
1  test/fixtures/status/current_file
... ...
@@ -0,0 +1 @@
  1
+current_file
1  test/fixtures/status/ignored_file
... ...
@@ -0,0 +1 @@
  1
+ignored_file
2  test/fixtures/status/modified_file
... ...
@@ -0,0 +1,2 @@
  1
+modified_file
  2
+modified_file
1  test/fixtures/status/new_file
... ...
@@ -0,0 +1 @@
  1
+new_file
2  test/fixtures/status/staged_changes
... ...
@@ -0,0 +1,2 @@
  1
+staged_changes
  2
+staged_changes
3  test/fixtures/status/staged_changes_modified_file
... ...
@@ -0,0 +1,3 @@
  1
+staged_changes_modified_file
  2
+staged_changes_modified_file
  3
+staged_changes_modified_file
1  test/fixtures/status/staged_delete_modified_file
... ...
@@ -0,0 +1 @@
  1
+staged_delete_modified_file
1  test/fixtures/status/staged_new_file
... ...
@@ -0,0 +1 @@
  1
+staged_new_file
2  test/fixtures/status/staged_new_file_modified_file
... ...
@@ -0,0 +1,2 @@
  1
+staged_new_file_modified_file
  2
+staged_new_file_modified_file
2  test/fixtures/status/subdir.txt
... ...
@@ -0,0 +1,2 @@
  1
+Is it a bird?
  2
+Is it a plane?
1  test/fixtures/status/subdir/current_file
... ...
@@ -0,0 +1 @@
  1
+subdir/current_file
2  test/fixtures/status/subdir/modified_file
... ...
@@ -0,0 +1,2 @@
  1
+subdir/modified_file
  2
+subdir/modified_file
1  test/fixtures/status/subdir/new_file
... ...
@@ -0,0 +1 @@
  1
+subdir/new_file
1  test/fixtures/status/这
... ...
@@ -0,0 +1 @@
  1
+This

0 notes on commit b93769f

Please sign in to comment.
Something went wrong with that request. Please try again.