From f093cd62c43da3f1c18bfba7ac3eadc671d5a6e7 Mon Sep 17 00:00:00 2001 From: nulltoken Date: Wed, 15 Aug 2012 18:49:01 +0200 Subject: [PATCH 1/3] Add unsymlinked.git test repository --- tests-clar/resources/unsymlinked.git/HEAD | 1 + tests-clar/resources/unsymlinked.git/config | 6 ++++++ tests-clar/resources/unsymlinked.git/description | 1 + .../resources/unsymlinked.git/hooks/README.sample | 5 +++++ tests-clar/resources/unsymlinked.git/info/exclude | 2 ++ .../08/8b64704e0d6b8bd061dea879418cb5442a3fbf | Bin 0 -> 49 bytes .../13/a5e939bca25940c069fd2169d993dba328e30b | Bin 0 -> 44 bytes .../19/bf568e59e3a0b363cafb4106226e62d4a4c41c | Bin 0 -> 29 bytes .../58/1fadd35b4cf320d102a152f918729011604773 | Bin 0 -> 47 bytes .../5c/87b6791e8b13da658a14d1ef7e09b5dc3bac8c | Bin 0 -> 78 bytes .../6f/e5f5398af85fb3de8a6aba0339b6d3bfa26a27 | Bin 0 -> 49 bytes .../7f/ccd75616ec188b8f1b23d67506a334cc34a49d | Bin 0 -> 132 bytes .../80/6999882bf91d24241e4077906b9017605eb1f3 | Bin 0 -> 170 bytes .../83/7d176303c5005505ec1e4a30231c40930c0230 | Bin 0 -> 44 bytes .../a8/595ccca04f40818ae0155c8f9c77a230e597b6 | 2 ++ .../cf/8f1cf5cce859c438d6cc067284cb5e161206e7 | Bin 0 -> 49 bytes .../d5/278d05c8607ec420bfee4cf219fbc0eeebfd6a | Bin 0 -> 49 bytes .../f4/e16fb76536591a41454194058d048d8e4dd2e9 | Bin 0 -> 44 bytes .../f9/e65619d93fdf2673882e0a261c5e93b1a84006 | Bin 0 -> 32 bytes .../resources/unsymlinked.git/refs/heads/exe-file | 1 + .../resources/unsymlinked.git/refs/heads/master | 1 + .../resources/unsymlinked.git/refs/heads/reg-file | 1 + 22 files changed, 20 insertions(+) create mode 100644 tests-clar/resources/unsymlinked.git/HEAD create mode 100644 tests-clar/resources/unsymlinked.git/config create mode 100644 tests-clar/resources/unsymlinked.git/description create mode 100644 tests-clar/resources/unsymlinked.git/hooks/README.sample create mode 100644 tests-clar/resources/unsymlinked.git/info/exclude create mode 100644 tests-clar/resources/unsymlinked.git/objects/08/8b64704e0d6b8bd061dea879418cb5442a3fbf create mode 100644 tests-clar/resources/unsymlinked.git/objects/13/a5e939bca25940c069fd2169d993dba328e30b create mode 100644 tests-clar/resources/unsymlinked.git/objects/19/bf568e59e3a0b363cafb4106226e62d4a4c41c create mode 100644 tests-clar/resources/unsymlinked.git/objects/58/1fadd35b4cf320d102a152f918729011604773 create mode 100644 tests-clar/resources/unsymlinked.git/objects/5c/87b6791e8b13da658a14d1ef7e09b5dc3bac8c create mode 100644 tests-clar/resources/unsymlinked.git/objects/6f/e5f5398af85fb3de8a6aba0339b6d3bfa26a27 create mode 100644 tests-clar/resources/unsymlinked.git/objects/7f/ccd75616ec188b8f1b23d67506a334cc34a49d create mode 100644 tests-clar/resources/unsymlinked.git/objects/80/6999882bf91d24241e4077906b9017605eb1f3 create mode 100644 tests-clar/resources/unsymlinked.git/objects/83/7d176303c5005505ec1e4a30231c40930c0230 create mode 100644 tests-clar/resources/unsymlinked.git/objects/a8/595ccca04f40818ae0155c8f9c77a230e597b6 create mode 100644 tests-clar/resources/unsymlinked.git/objects/cf/8f1cf5cce859c438d6cc067284cb5e161206e7 create mode 100644 tests-clar/resources/unsymlinked.git/objects/d5/278d05c8607ec420bfee4cf219fbc0eeebfd6a create mode 100644 tests-clar/resources/unsymlinked.git/objects/f4/e16fb76536591a41454194058d048d8e4dd2e9 create mode 100644 tests-clar/resources/unsymlinked.git/objects/f9/e65619d93fdf2673882e0a261c5e93b1a84006 create mode 100644 tests-clar/resources/unsymlinked.git/refs/heads/exe-file create mode 100644 tests-clar/resources/unsymlinked.git/refs/heads/master create mode 100644 tests-clar/resources/unsymlinked.git/refs/heads/reg-file diff --git a/tests-clar/resources/unsymlinked.git/HEAD b/tests-clar/resources/unsymlinked.git/HEAD new file mode 100644 index 000000000..cb089cd89 --- /dev/null +++ b/tests-clar/resources/unsymlinked.git/HEAD @@ -0,0 +1 @@ +ref: refs/heads/master diff --git a/tests-clar/resources/unsymlinked.git/config b/tests-clar/resources/unsymlinked.git/config new file mode 100644 index 000000000..f57351fd5 --- /dev/null +++ b/tests-clar/resources/unsymlinked.git/config @@ -0,0 +1,6 @@ +[core] + bare = true + repositoryformatversion = 0 + filemode = false + logallrefupdates = true + ignorecase = true diff --git a/tests-clar/resources/unsymlinked.git/description b/tests-clar/resources/unsymlinked.git/description new file mode 100644 index 000000000..498b267a8 --- /dev/null +++ b/tests-clar/resources/unsymlinked.git/description @@ -0,0 +1 @@ +Unnamed repository; edit this file 'description' to name the repository. diff --git a/tests-clar/resources/unsymlinked.git/hooks/README.sample b/tests-clar/resources/unsymlinked.git/hooks/README.sample new file mode 100644 index 000000000..d125ec83f --- /dev/null +++ b/tests-clar/resources/unsymlinked.git/hooks/README.sample @@ -0,0 +1,5 @@ +#!/bin/sh +# +# Place appropriately named executable hook scripts into this directory +# to intercept various actions that git takes. See `git help hooks` for +# more information. diff --git a/tests-clar/resources/unsymlinked.git/info/exclude b/tests-clar/resources/unsymlinked.git/info/exclude new file mode 100644 index 000000000..6d05881d3 --- /dev/null +++ b/tests-clar/resources/unsymlinked.git/info/exclude @@ -0,0 +1,2 @@ +# File patterns to ignore; see `git help ignore` for more information. +# Lines that start with '#' are comments. diff --git a/tests-clar/resources/unsymlinked.git/objects/08/8b64704e0d6b8bd061dea879418cb5442a3fbf b/tests-clar/resources/unsymlinked.git/objects/08/8b64704e0d6b8bd061dea879418cb5442a3fbf new file mode 100644 index 0000000000000000000000000000000000000000..953262fa919d9724bbc2eebd40d804cf99eed6fe GIT binary patch literal 49 zcmV-10M7q-0V^p=O;s>9VlXr?FgG<-@GI5JVEFkgO!B7veYN5aJuWqwxXBw=IIsZ# H{)5VqnO?#JWGIjpOIm>5FUav}01DB)$YM%4kYxsy1Y}&BJp708OM2 ABLDyZ literal 0 HcmV?d00001 diff --git a/tests-clar/resources/unsymlinked.git/objects/19/bf568e59e3a0b363cafb4106226e62d4a4c41c b/tests-clar/resources/unsymlinked.git/objects/19/bf568e59e3a0b363cafb4106226e62d4a4c41c new file mode 100644 index 0000000000000000000000000000000000000000..94afd01e8af764ea40f44bec81690f89d89e17d4 GIT binary patch literal 29 lcmbU}D`Lw3mnNGEh>O?-~GU CBoJ!= literal 0 HcmV?d00001 diff --git a/tests-clar/resources/unsymlinked.git/objects/5c/87b6791e8b13da658a14d1ef7e09b5dc3bac8c b/tests-clar/resources/unsymlinked.git/objects/5c/87b6791e8b13da658a14d1ef7e09b5dc3bac8c new file mode 100644 index 0000000000000000000000000000000000000000..67eb14930c0a2efe84dafba6deab01cc1cd2b1fc GIT binary patch literal 78 zcmV-U0I~mg0V^p=O;s>6WiT-S0)@=H^higY-T`ByRX=H%OpH6C+A kROBaRB{Q7wm-%|;MdT5SYiHPsT29A_39&r~0QEQ>yDWYqH2?qr literal 0 HcmV?d00001 diff --git a/tests-clar/resources/unsymlinked.git/objects/6f/e5f5398af85fb3de8a6aba0339b6d3bfa26a27 b/tests-clar/resources/unsymlinked.git/objects/6f/e5f5398af85fb3de8a6aba0339b6d3bfa26a27 new file mode 100644 index 0000000000000000000000000000000000000000..c1ea0de75fac99058980349942fa053ac8eff434 GIT binary patch literal 49 zcmV-10M7q-0V^p=O;s>9VK6ZO0)@=HRuD( literal 0 HcmV?d00001 diff --git a/tests-clar/resources/unsymlinked.git/objects/7f/ccd75616ec188b8f1b23d67506a334cc34a49d b/tests-clar/resources/unsymlinked.git/objects/7f/ccd75616ec188b8f1b23d67506a334cc34a49d new file mode 100644 index 0000000000000000000000000000000000000000..028505563894257f00f3e1fca04bae797e1b9702 GIT binary patch literal 132 zcmV-~0DJ#<0hNtA3PLdu0IhS1?S+t--#!rWUBK2l*{mdJ48&M?dmnfLtAT-GsJB)p z=-_vAFoPou$%jQVCT()`4x_eN^DVGilFMXLBqR~vv-AP$4;Kk*V>p)D&a?1fNxhvw m8|#!sYZ3P9pp@9`wwwHSD6VxDi17NfM}6Lb#AtvXVyQ$W-m;%S* zoELGv_-j+;xwdoC?GHbiZUgkW?c;lGn9y>LFEY*t_Br`X7q-mmZQpwf{|=SbTDEfB Y(P%%`Nrfiv&qtZm_Xo6k0gMMqi*V>scmMzZ literal 0 HcmV?d00001 diff --git a/tests-clar/resources/unsymlinked.git/objects/83/7d176303c5005505ec1e4a30231c40930c0230 b/tests-clar/resources/unsymlinked.git/objects/83/7d176303c5005505ec1e4a30231c40930c0230 new file mode 100644 index 0000000000000000000000000000000000000000..189ab044d00cfed1ddaeb48ceab4441db5ba9cef GIT binary patch literal 44 zcmV+{0Mq|?0V^p=O;s?mWH2!R0tLTP29EBO0zcmD?hA?cR#ZCnY<1DH-wy!N9VlXr?Ff%bx@GI5JVEFkgO!B7veYN5aJuWqwxXBw=IIsZ# H{$mYJ)20*$ literal 0 HcmV?d00001 diff --git a/tests-clar/resources/unsymlinked.git/objects/d5/278d05c8607ec420bfee4cf219fbc0eeebfd6a b/tests-clar/resources/unsymlinked.git/objects/d5/278d05c8607ec420bfee4cf219fbc0eeebfd6a new file mode 100644 index 0000000000000000000000000000000000000000..c1b6a5101afd02d6030b0f2fe51bab72a2e557fb GIT binary patch literal 49 zcmV-10M7q-0V^p=O;s>9VK6ZO0)@=H)5VqnO?#JWGI?ekxw`15-@Y?2D!@*xxwLQ;jKV)J^S Date: Wed, 6 Feb 2013 16:06:17 +0100 Subject: [PATCH 2/3] diff: refactor git_diff_tree_to_tree() tests --- tests-clar/diff/tree.c | 63 ++++++++++++------------------------------ 1 file changed, 18 insertions(+), 45 deletions(-) diff --git a/tests-clar/diff/tree.c b/tests-clar/diff/tree.c index 442e53b25..cd951a15a 100644 --- a/tests-clar/diff/tree.c +++ b/tests-clar/diff/tree.c @@ -2,13 +2,28 @@ #include "diff_helpers.h" static git_repository *g_repo = NULL; +static git_diff_options opts; +static git_diff_list *diff; +static git_tree *a, *b; +static diff_expects exp; void test_diff_tree__initialize(void) { + GIT_INIT_STRUCTURE(&opts, GIT_DIFF_OPTIONS_VERSION); + + memset(&exp, 0, sizeof(exp)); + + diff = NULL; + a = NULL; + b = NULL; } void test_diff_tree__cleanup(void) { + git_diff_list_free(diff); + git_tree_free(a); + git_tree_free(b); + cl_git_sandbox_cleanup(); } @@ -18,10 +33,7 @@ void test_diff_tree__0(void) const char *a_commit = "605812a"; const char *b_commit = "370fe9ec22"; const char *c_commit = "f5b0af1fb4f5c"; - git_tree *a, *b, *c; - git_diff_options opts = GIT_DIFF_OPTIONS_INIT; - git_diff_list *diff = NULL; - diff_expects exp; + git_tree *c; g_repo = cl_git_sandbox_init("attr"); @@ -32,7 +44,6 @@ void test_diff_tree__0(void) opts.context_lines = 1; opts.interhunk_lines = 1; - memset(&exp, 0, sizeof(exp)); cl_git_pass(git_diff_tree_to_tree(&diff, g_repo, a, b, &opts)); @@ -73,10 +84,6 @@ void test_diff_tree__0(void) cl_assert_equal_i(1, exp.line_adds); cl_assert_equal_i(7 + 14, exp.line_dels); - git_diff_list_free(diff); - - git_tree_free(a); - git_tree_free(b); git_tree_free(c); } @@ -87,9 +94,7 @@ void test_diff_tree__options(void) const char *b_commit = "605812ab7fe421fdd"; const char *c_commit = "f5b0af1fb4f5"; const char *d_commit = "a97cc019851"; - git_tree *a, *b, *c, *d; - git_diff_options opts = {0}; - git_diff_list *diff = NULL; + git_tree *c, *d; diff_expects actual; int test_ab_or_cd[] = { 0, 0, 0, 0, 1, 1, 1, 1, 1 }; git_diff_options test_options[] = { @@ -164,8 +169,6 @@ void test_diff_tree__options(void) diff = NULL; } - git_tree_free(a); - git_tree_free(b); git_tree_free(c); git_tree_free(d); } @@ -174,10 +177,6 @@ void test_diff_tree__bare(void) { const char *a_commit = "8496071c1b46c85"; const char *b_commit = "be3563ae3f79"; - git_tree *a, *b; - git_diff_options opts = GIT_DIFF_OPTIONS_INIT; - git_diff_list *diff = NULL; - diff_expects exp; g_repo = cl_git_sandbox_init("testrepo.git"); @@ -187,8 +186,6 @@ void test_diff_tree__bare(void) opts.context_lines = 1; opts.interhunk_lines = 1; - memset(&exp, 0, sizeof(exp)); - cl_git_pass(git_diff_tree_to_tree(&diff, g_repo, a, b, &opts)); cl_git_pass(git_diff_foreach( @@ -205,10 +202,6 @@ void test_diff_tree__bare(void) cl_assert_equal_i(0, exp.line_ctxt); cl_assert_equal_i(3, exp.line_adds); cl_assert_equal_i(1, exp.line_dels); - - git_diff_list_free(diff); - git_tree_free(a); - git_tree_free(b); } void test_diff_tree__merge(void) @@ -217,9 +210,8 @@ void test_diff_tree__merge(void) const char *a_commit = "605812a"; const char *b_commit = "370fe9ec22"; const char *c_commit = "f5b0af1fb4f5c"; - git_tree *a, *b, *c; + git_tree *c; git_diff_list *diff1 = NULL, *diff2 = NULL; - diff_expects exp; g_repo = cl_git_sandbox_init("attr"); @@ -231,16 +223,12 @@ void test_diff_tree__merge(void) cl_git_pass(git_diff_tree_to_tree(&diff2, g_repo, c, b, NULL)); - git_tree_free(a); - git_tree_free(b); git_tree_free(c); cl_git_pass(git_diff_merge(diff1, diff2)); git_diff_list_free(diff2); - memset(&exp, 0, sizeof(exp)); - cl_git_pass(git_diff_foreach( diff1, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp)); @@ -263,9 +251,6 @@ void test_diff_tree__larger_hunks(void) { const char *a_commit = "d70d245ed97ed2aa596dd1af6536e4bfdb047b69"; const char *b_commit = "7a9e0b02e63179929fed24f0a3e0f19168114d10"; - git_tree *a, *b; - git_diff_options opts = GIT_DIFF_OPTIONS_INIT; - git_diff_list *diff = NULL; size_t d, num_d, h, num_h, l, num_l, header_len, line_len; const git_diff_delta *delta; git_diff_patch *patch; @@ -312,21 +297,12 @@ void test_diff_tree__larger_hunks(void) cl_git_fail(git_diff_get_patch(&patch, &delta, diff, num_d)); cl_assert_equal_i(2, (int)num_d); - - git_diff_list_free(diff); - diff = NULL; - - git_tree_free(a); - git_tree_free(b); } void test_diff_tree__checks_options_version(void) { const char *a_commit = "8496071c1b46c85"; const char *b_commit = "be3563ae3f79"; - git_tree *a, *b; - git_diff_options opts = GIT_DIFF_OPTIONS_INIT; - git_diff_list *diff = NULL; const git_error *err; g_repo = cl_git_sandbox_init("testrepo.git"); @@ -343,7 +319,4 @@ void test_diff_tree__checks_options_version(void) opts.version = 1024; cl_git_fail(git_diff_tree_to_tree(&diff, g_repo, a, b, &opts)); err = giterr_last(); - - git_tree_free(a); - git_tree_free(b); } From e8993455d1af01cb17e9108718a99e5181c64290 Mon Sep 17 00:00:00 2001 From: nulltoken Date: Wed, 15 Aug 2012 20:08:09 +0200 Subject: [PATCH 3/3] diff: Enhance tree-to-tree diff test coverage These tests are related to issue libgit2/libgit2sharp#196 --- tests-clar/diff/tree.c | 109 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) diff --git a/tests-clar/diff/tree.c b/tests-clar/diff/tree.c index cd951a15a..c60acd816 100644 --- a/tests-clar/diff/tree.c +++ b/tests-clar/diff/tree.c @@ -25,6 +25,7 @@ void test_diff_tree__cleanup(void) git_tree_free(b); cl_git_sandbox_cleanup(); + } void test_diff_tree__0(void) @@ -320,3 +321,111 @@ void test_diff_tree__checks_options_version(void) cl_git_fail(git_diff_tree_to_tree(&diff, g_repo, a, b, &opts)); err = giterr_last(); } + +void process_tree_to_tree_diffing( + const char *old_commit, + const char *new_commit) +{ + g_repo = cl_git_sandbox_init("unsymlinked.git"); + + cl_assert((a = resolve_commit_oid_to_tree(g_repo, old_commit)) != NULL); + cl_assert((b = resolve_commit_oid_to_tree(g_repo, new_commit)) != NULL); + + cl_git_pass(git_diff_tree_to_tree(&diff, g_repo, a, b, &opts)); + + cl_git_pass(git_diff_foreach( + diff, diff_file_cb, NULL, NULL, &exp)); +} + +void test_diff_tree__symlink_blob_mode_changed_to_regular_file(void) +{ + /* + * $ git diff 7fccd7..806999 + * diff --git a/include/Nu/Nu.h b/include/Nu/Nu.h + * deleted file mode 120000 + * index 19bf568..0000000 + * --- a/include/Nu/Nu.h + * +++ /dev/null + * @@ -1 +0,0 @@ + * -../../objc/Nu.h + * \ No newline at end of file + * diff --git a/include/Nu/Nu.h b/include/Nu/Nu.h + * new file mode 100644 + * index 0000000..f9e6561 + * --- /dev/null + * +++ b/include/Nu/Nu.h + * @@ -0,0 +1 @@ + * +awesome content + * diff --git a/objc/Nu.h b/objc/Nu.h + * deleted file mode 100644 + * index f9e6561..0000000 + * --- a/objc/Nu.h + * +++ /dev/null + * @@ -1 +0,0 @@ + * -awesome content + */ + + process_tree_to_tree_diffing("7fccd7", "806999"); + + cl_assert_equal_i(3, exp.files); + cl_assert_equal_i(2, exp.file_status[GIT_DELTA_DELETED]); + cl_assert_equal_i(0, exp.file_status[GIT_DELTA_MODIFIED]); + cl_assert_equal_i(1, exp.file_status[GIT_DELTA_ADDED]); + cl_assert_equal_i(0, exp.file_status[GIT_DELTA_TYPECHANGE]); +} + +void test_diff_tree__symlink_blob_mode_changed_to_regular_file_as_typechange(void) +{ + /* + * $ git diff 7fccd7..a8595c + * diff --git a/include/Nu/Nu.h b/include/Nu/Nu.h + * deleted file mode 120000 + * index 19bf568..0000000 + * --- a/include/Nu/Nu.h + * +++ /dev/null + * @@ -1 +0,0 @@ + * -../../objc/Nu.h + * \ No newline at end of file + * diff --git a/include/Nu/Nu.h b/include/Nu/Nu.h + * new file mode 100755 + * index 0000000..f9e6561 + * --- /dev/null + * +++ b/include/Nu/Nu.h + * @@ -0,0 +1 @@ + * +awesome content + * diff --git a/objc/Nu.h b/objc/Nu.h + * deleted file mode 100644 + * index f9e6561..0000000 + * --- a/objc/Nu.h + * +++ /dev/null + * @@ -1 +0,0 @@ + * -awesome content + */ + + opts.flags = GIT_DIFF_INCLUDE_TYPECHANGE; + process_tree_to_tree_diffing("7fccd7", "a8595c"); + + cl_assert_equal_i(2, exp.files); + cl_assert_equal_i(1, exp.file_status[GIT_DELTA_DELETED]); + cl_assert_equal_i(0, exp.file_status[GIT_DELTA_MODIFIED]); + cl_assert_equal_i(0, exp.file_status[GIT_DELTA_ADDED]); + cl_assert_equal_i(1, exp.file_status[GIT_DELTA_TYPECHANGE]); +} + +void test_diff_tree__regular_blob_mode_changed_to_executable_file(void) +{ + /* + * $ git diff 806999..a8595c + * diff --git a/include/Nu/Nu.h b/include/Nu/Nu.h + * old mode 100644 + * new mode 100755 + */ + + process_tree_to_tree_diffing("806999", "a8595c"); + + cl_assert_equal_i(1, exp.files); + cl_assert_equal_i(0, exp.file_status[GIT_DELTA_DELETED]); + cl_assert_equal_i(1, exp.file_status[GIT_DELTA_MODIFIED]); + cl_assert_equal_i(0, exp.file_status[GIT_DELTA_ADDED]); + cl_assert_equal_i(0, exp.file_status[GIT_DELTA_TYPECHANGE]); +}