|
2 | 2 | #include "git2/repository.h" |
3 | 3 | #include "git2/sys/index.h" |
4 | 4 | #include "fileops.h" |
| 5 | +#include "repository.h" |
5 | 6 |
|
6 | 7 | static git_repository *g_repo; |
7 | 8 | static git_index *g_index; |
@@ -184,28 +185,35 @@ static void ensure_workdir(const char *path, int mode, const char *oid_str) |
184 | 185 | ensure_workdir_oid(path, oid_str); |
185 | 186 | } |
186 | 187 |
|
187 | | -static void ensure_workdir_link(const char *path, const char *target) |
| 188 | +static void ensure_workdir_link( |
| 189 | + git_repository *repo, |
| 190 | + const char *path, |
| 191 | + const char *target) |
188 | 192 | { |
189 | | -#ifdef GIT_WIN32 |
190 | | - ensure_workdir_contents(path, target); |
191 | | -#else |
192 | | - git_buf fullpath = GIT_BUF_INIT; |
193 | | - char actual[1024]; |
194 | | - struct stat st; |
195 | | - int len; |
| 193 | + int symlinks; |
196 | 194 |
|
197 | | - cl_git_pass( |
198 | | - git_buf_joinpath(&fullpath, git_repository_workdir(g_repo), path)); |
| 195 | + cl_git_pass(git_repository__cvar(&symlinks, repo, GIT_CVAR_SYMLINKS)); |
199 | 196 |
|
200 | | - cl_git_pass(p_lstat(git_buf_cstr(&fullpath), &st)); |
201 | | - cl_assert(S_ISLNK(st.st_mode)); |
| 197 | + if (!symlinks) { |
| 198 | + ensure_workdir_contents(path, target); |
| 199 | + } else { |
| 200 | + git_buf fullpath = GIT_BUF_INIT; |
| 201 | + char actual[1024]; |
| 202 | + struct stat st; |
| 203 | + int len; |
202 | 204 |
|
203 | | - cl_assert((len = p_readlink(git_buf_cstr(&fullpath), actual, 1024)) > 0); |
204 | | - actual[len] = '\0'; |
205 | | - cl_assert(strcmp(actual, target) == 0); |
| 205 | + cl_git_pass( |
| 206 | + git_buf_joinpath(&fullpath, git_repository_workdir(g_repo), path)); |
206 | 207 |
|
207 | | - git_buf_dispose(&fullpath); |
208 | | -#endif |
| 208 | + cl_git_pass(p_lstat(git_buf_cstr(&fullpath), &st)); |
| 209 | + cl_assert(S_ISLNK(st.st_mode)); |
| 210 | + |
| 211 | + cl_assert((len = p_readlink(git_buf_cstr(&fullpath), actual, 1024)) > 0); |
| 212 | + actual[len] = '\0'; |
| 213 | + cl_assert(strcmp(actual, target) == 0); |
| 214 | + |
| 215 | + git_buf_dispose(&fullpath); |
| 216 | + } |
209 | 217 | } |
210 | 218 |
|
211 | 219 | void test_checkout_conflict__ignored(void) |
@@ -415,8 +423,8 @@ void test_checkout_conflict__links(void) |
415 | 423 | cl_git_pass(git_checkout_index(g_repo, g_index, &opts)); |
416 | 424 |
|
417 | 425 | /* Conflicts with links always keep the ours side (even with -Xtheirs) */ |
418 | | - ensure_workdir_link("link-1", LINK_OURS_TARGET); |
419 | | - ensure_workdir_link("link-2", LINK_OURS_TARGET); |
| 426 | + ensure_workdir_link(g_repo, "link-1", LINK_OURS_TARGET); |
| 427 | + ensure_workdir_link(g_repo, "link-2", LINK_OURS_TARGET); |
420 | 428 | } |
421 | 429 |
|
422 | 430 | void test_checkout_conflict__add_add(void) |
@@ -684,7 +692,7 @@ void test_checkout_conflict__renames(void) |
684 | 692 | void test_checkout_conflict__rename_keep_ours(void) |
685 | 693 | { |
686 | 694 | git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT; |
687 | | - |
| 695 | + |
688 | 696 | struct checkout_index_entry checkout_index_entries[] = { |
689 | 697 | { 0100644, "68c6c84b091926c7d90aa6a79b2bc3bb6adccd8e", 0, "0a-no-change.txt" }, |
690 | 698 | { 0100644, "f0ce2b8e4986084d9b308fb72709e414c23eb5e6", 0, "0b-duplicated-in-ours.txt" }, |
@@ -728,122 +736,122 @@ void test_checkout_conflict__rename_keep_ours(void) |
728 | 736 | { 0100644, "b42712cfe99a1a500b2a51fe984e0b8a7702ba11", 2, "7-both-renamed.txt" }, |
729 | 737 | { 0100644, "b69fe837e4cecfd4c9a40cdca7c138468687df07", 3, "7-both-renamed.txt" } |
730 | 738 | }; |
731 | | - |
| 739 | + |
732 | 740 | struct checkout_name_entry checkout_name_entries[] = { |
733 | 741 | { |
734 | 742 | "3a-renamed-in-ours-deleted-in-theirs.txt", |
735 | 743 | "3a-newname-in-ours-deleted-in-theirs.txt", |
736 | 744 | "" |
737 | 745 | }, |
738 | | - |
| 746 | + |
739 | 747 | { |
740 | 748 | "3b-renamed-in-theirs-deleted-in-ours.txt", |
741 | 749 | "", |
742 | 750 | "3b-newname-in-theirs-deleted-in-ours.txt" |
743 | 751 | }, |
744 | | - |
| 752 | + |
745 | 753 | { |
746 | 754 | "4a-renamed-in-ours-added-in-theirs.txt", |
747 | 755 | "4a-newname-in-ours-added-in-theirs.txt", |
748 | 756 | "" |
749 | 757 | }, |
750 | | - |
| 758 | + |
751 | 759 | { |
752 | 760 | "4b-renamed-in-theirs-added-in-ours.txt", |
753 | 761 | "", |
754 | 762 | "4b-newname-in-theirs-added-in-ours.txt" |
755 | 763 | }, |
756 | | - |
| 764 | + |
757 | 765 | { |
758 | 766 | "5a-renamed-in-ours-added-in-theirs.txt", |
759 | 767 | "5a-newname-in-ours-added-in-theirs.txt", |
760 | 768 | "5a-renamed-in-ours-added-in-theirs.txt" |
761 | 769 | }, |
762 | | - |
| 770 | + |
763 | 771 | { |
764 | 772 | "5b-renamed-in-theirs-added-in-ours.txt", |
765 | 773 | "5b-renamed-in-theirs-added-in-ours.txt", |
766 | 774 | "5b-newname-in-theirs-added-in-ours.txt" |
767 | 775 | }, |
768 | | - |
| 776 | + |
769 | 777 | { |
770 | 778 | "6-both-renamed-1-to-2.txt", |
771 | 779 | "6-both-renamed-1-to-2-ours.txt", |
772 | 780 | "6-both-renamed-1-to-2-theirs.txt" |
773 | 781 | }, |
774 | | - |
| 782 | + |
775 | 783 | { |
776 | 784 | "7-both-renamed-side-1.txt", |
777 | 785 | "7-both-renamed.txt", |
778 | 786 | "7-both-renamed-side-1.txt" |
779 | 787 | }, |
780 | | - |
| 788 | + |
781 | 789 | { |
782 | 790 | "7-both-renamed-side-2.txt", |
783 | 791 | "7-both-renamed-side-2.txt", |
784 | 792 | "7-both-renamed.txt" |
785 | 793 | } |
786 | 794 | }; |
787 | | - |
| 795 | + |
788 | 796 | opts.checkout_strategy |= GIT_CHECKOUT_SAFE | GIT_CHECKOUT_USE_OURS; |
789 | | - |
| 797 | + |
790 | 798 | create_index(checkout_index_entries, 41); |
791 | 799 | create_index_names(checkout_name_entries, 9); |
792 | 800 | cl_git_pass(git_index_write(g_index)); |
793 | | - |
| 801 | + |
794 | 802 | cl_git_pass(git_checkout_index(g_repo, g_index, &opts)); |
795 | | - |
| 803 | + |
796 | 804 | ensure_workdir("0a-no-change.txt", |
797 | 805 | 0100644, "68c6c84b091926c7d90aa6a79b2bc3bb6adccd8e"); |
798 | | - |
| 806 | + |
799 | 807 | ensure_workdir("0b-duplicated-in-ours.txt", |
800 | 808 | 0100644, "f0ce2b8e4986084d9b308fb72709e414c23eb5e6"); |
801 | | - |
| 809 | + |
802 | 810 | ensure_workdir("0b-rewritten-in-ours.txt", |
803 | 811 | 0100644, "e376fbdd06ebf021c92724da9f26f44212734e3e"); |
804 | | - |
| 812 | + |
805 | 813 | ensure_workdir("0c-duplicated-in-theirs.txt", |
806 | 814 | 0100644, "2f56120107d680129a5d9791b521cb1e73a2ed31"); |
807 | | - |
| 815 | + |
808 | 816 | ensure_workdir("0c-rewritten-in-theirs.txt", |
809 | 817 | 0100644, "efc9121fdedaf08ba180b53ebfbcf71bd488ed09"); |
810 | | - |
| 818 | + |
811 | 819 | ensure_workdir("1a-newname-in-ours-edited-in-theirs.txt", |
812 | 820 | 0100644, "0d872f8e871a30208305978ecbf9e66d864f1638"); |
813 | | - |
| 821 | + |
814 | 822 | ensure_workdir("1a-newname-in-ours.txt", |
815 | 823 | 0100644, "d0d4594e16f2e19107e3fa7ea63e7aaaff305ffb"); |
816 | | - |
| 824 | + |
817 | 825 | ensure_workdir("1b-newname-in-theirs-edited-in-ours.txt", |
818 | 826 | 0100644, "ed9523e62e453e50dd9be1606af19399b96e397a"); |
819 | | - |
| 827 | + |
820 | 828 | ensure_workdir("1b-newname-in-theirs.txt", |
821 | 829 | 0100644, "2b5f1f181ee3b58ea751f5dd5d8f9b445520a136"); |
822 | | - |
| 830 | + |
823 | 831 | ensure_workdir("2-newname-in-both.txt", |
824 | 832 | 0100644, "178940b450f238a56c0d75b7955cb57b38191982"); |
825 | 833 |
|
826 | 834 | ensure_workdir("3a-newname-in-ours-deleted-in-theirs.txt", |
827 | 835 | 0100644, "18cb316b1cefa0f8a6946f0e201a8e1a6f845ab9"); |
828 | | - |
| 836 | + |
829 | 837 | ensure_workdir("3b-newname-in-theirs-deleted-in-ours.txt", |
830 | 838 | 0100644, "36219b49367146cb2e6a1555b5a9ebd4d0328495"); |
831 | | - |
| 839 | + |
832 | 840 | ensure_workdir("4a-newname-in-ours-added-in-theirs.txt", |
833 | 841 | 0100644, "227792b52aaa0b238bea00ec7e509b02623f168c"); |
834 | | - |
| 842 | + |
835 | 843 | ensure_workdir("4b-newname-in-theirs-added-in-ours.txt", |
836 | 844 | 0100644, "de872ee3618b894992e9d1e18ba2ebe256a112f9"); |
837 | | - |
| 845 | + |
838 | 846 | ensure_workdir("5a-newname-in-ours-added-in-theirs.txt", |
839 | 847 | 0100644, "d3719a5ae8e4d92276b5313ce976f6ee5af2b436"); |
840 | | - |
| 848 | + |
841 | 849 | ensure_workdir("5b-newname-in-theirs-added-in-ours.txt", |
842 | 850 | 0100644, "385c8a0f26ddf79e9041e15e17dc352ed2c4cced"); |
843 | 851 |
|
844 | 852 | ensure_workdir("6-both-renamed-1-to-2-ours.txt", |
845 | 853 | 0100644, "d8fa77b6833082c1ea36b7828a582d4c43882450"); |
846 | | - |
| 854 | + |
847 | 855 | ensure_workdir("7-both-renamed.txt", |
848 | 856 | 0100644, "b42712cfe99a1a500b2a51fe984e0b8a7702ba11"); |
849 | 857 | } |
|
0 commit comments