|
31 | 31 |
|
32 | 32 | # pygit2
|
33 | 33 | import pygit2
|
34 |
| -from pygit2 import init_repository, clone_repository, discover_repository |
| 34 | +from pygit2 import init_repository, clone_repository, discover_repository, IndexEntry |
35 | 35 | from pygit2 import Oid
|
36 | 36 | from pygit2.enums import (
|
37 | 37 | CheckoutNotify,
|
|
41 | 41 | RepositoryOpenFlag,
|
42 | 42 | RepositoryState,
|
43 | 43 | ResetMode,
|
44 |
| - StashApplyProgress, |
| 44 | + StashApplyProgress, FileMode, |
45 | 45 | )
|
46 | 46 | from . import utils
|
47 | 47 |
|
@@ -985,3 +985,114 @@ def test_repository_hashfile_filter(testrepo):
|
985 | 985 | testrepo.config['core.safecrlf'] = 'fail'
|
986 | 986 | with pytest.raises(pygit2.GitError):
|
987 | 987 | h = testrepo.hashfile('hello.txt')
|
| 988 | + |
| 989 | + |
| 990 | +def test_merge_file_from_index_deprecated(testrepo): |
| 991 | + hello_txt = testrepo.index['hello.txt'] |
| 992 | + hello_txt_executable = IndexEntry(hello_txt.path, hello_txt.id, FileMode.BLOB_EXECUTABLE) |
| 993 | + hello_world = IndexEntry("hello_world.txt", hello_txt.id, hello_txt.mode) |
| 994 | + other_file_blob = testrepo.create_blob("Data that will clash with hello.txt") |
| 995 | + |
| 996 | + # no change |
| 997 | + res = testrepo.merge_file_from_index(hello_txt, hello_txt, hello_txt) |
| 998 | + assert res == testrepo.get(hello_txt.id).data.decode() |
| 999 | + |
| 1000 | + # executable switch on ours |
| 1001 | + res = testrepo.merge_file_from_index(hello_txt, hello_txt_executable, hello_txt) |
| 1002 | + assert res == testrepo.get(hello_txt.id).data.decode() |
| 1003 | + |
| 1004 | + # executable switch on theirs |
| 1005 | + res = testrepo.merge_file_from_index(hello_txt, hello_txt, hello_txt_executable) |
| 1006 | + assert res == testrepo.get(hello_txt.id).data.decode() |
| 1007 | + |
| 1008 | + # executable switch on both |
| 1009 | + res = testrepo.merge_file_from_index(hello_txt, hello_txt_executable, hello_txt_executable) |
| 1010 | + assert res == testrepo.get(hello_txt.id).data.decode() |
| 1011 | + |
| 1012 | + # path switch on ours |
| 1013 | + res = testrepo.merge_file_from_index(hello_txt, hello_world, hello_txt) |
| 1014 | + assert res == testrepo.get(hello_txt.id).data.decode() |
| 1015 | + |
| 1016 | + # path switch on theirs |
| 1017 | + res = testrepo.merge_file_from_index(hello_txt, hello_txt, hello_world) |
| 1018 | + assert res == testrepo.get(hello_txt.id).data.decode() |
| 1019 | + |
| 1020 | + # path switch on both |
| 1021 | + res = testrepo.merge_file_from_index(hello_txt, hello_world, hello_world) |
| 1022 | + assert res == testrepo.get(hello_txt.id).data.decode() |
| 1023 | + |
| 1024 | + # path switch on ours, executable flag switch on theirs |
| 1025 | + res = testrepo.merge_file_from_index(hello_txt, hello_world, hello_txt_executable) |
| 1026 | + assert res == testrepo.get(hello_txt.id).data.decode() |
| 1027 | + |
| 1028 | + # path switch on theirs, executable flag switch on ours |
| 1029 | + res = testrepo.merge_file_from_index(hello_txt, hello_txt_executable, hello_world) |
| 1030 | + assert res == testrepo.get(hello_txt.id).data.decode() |
| 1031 | + |
| 1032 | +def test_merge_file_from_index_non_deprecated(testrepo): |
| 1033 | + hello_txt = testrepo.index['hello.txt'] |
| 1034 | + hello_txt_executable = IndexEntry(hello_txt.path, hello_txt.id, FileMode.BLOB_EXECUTABLE) |
| 1035 | + hello_world = IndexEntry("hello_world.txt", hello_txt.id, hello_txt.mode) |
| 1036 | + |
| 1037 | + # no change |
| 1038 | + res = testrepo.merge_file_from_index(hello_txt, hello_txt, hello_txt, use_deprecated=False) |
| 1039 | + assert res.automergeable |
| 1040 | + assert res.path == hello_txt.path |
| 1041 | + assert res.mode == hello_txt.mode |
| 1042 | + assert res.contents == testrepo.get(hello_txt.id).data.decode() |
| 1043 | + |
| 1044 | + # executable switch on ours |
| 1045 | + res = testrepo.merge_file_from_index(hello_txt, hello_txt_executable, hello_txt, use_deprecated=False) |
| 1046 | + assert res.automergeable |
| 1047 | + assert res.path == hello_txt.path |
| 1048 | + assert res.mode == hello_txt_executable.mode |
| 1049 | + assert res.contents == testrepo.get(hello_txt.id).data.decode() |
| 1050 | + |
| 1051 | + # executable switch on theirs |
| 1052 | + res = testrepo.merge_file_from_index(hello_txt, hello_txt, hello_txt_executable, use_deprecated=False) |
| 1053 | + assert res.automergeable |
| 1054 | + assert res.path == hello_txt.path |
| 1055 | + assert res.mode == hello_txt_executable.mode |
| 1056 | + assert res.contents == testrepo.get(hello_txt.id).data.decode() |
| 1057 | + |
| 1058 | + # executable switch on both |
| 1059 | + res = testrepo.merge_file_from_index(hello_txt, hello_txt_executable, hello_txt_executable, use_deprecated=False) |
| 1060 | + assert res.automergeable |
| 1061 | + assert res.path == hello_txt.path |
| 1062 | + assert res.mode == hello_txt_executable.mode |
| 1063 | + assert res.contents == testrepo.get(hello_txt.id).data.decode() |
| 1064 | + |
| 1065 | + # path switch on ours |
| 1066 | + res = testrepo.merge_file_from_index(hello_txt, hello_world, hello_txt, use_deprecated=False) |
| 1067 | + assert res.automergeable |
| 1068 | + assert res.path == hello_world.path |
| 1069 | + assert res.mode == hello_txt.mode |
| 1070 | + assert res.contents == testrepo.get(hello_txt.id).data.decode() |
| 1071 | + |
| 1072 | + # path switch on theirs |
| 1073 | + res = testrepo.merge_file_from_index(hello_txt, hello_txt, hello_world, use_deprecated=False) |
| 1074 | + assert res.automergeable |
| 1075 | + assert res.path == hello_world.path |
| 1076 | + assert res.mode == hello_txt.mode |
| 1077 | + assert res.contents == testrepo.get(hello_txt.id).data.decode() |
| 1078 | + |
| 1079 | + # path switch on both |
| 1080 | + res = testrepo.merge_file_from_index(hello_txt, hello_world, hello_world, use_deprecated=False) |
| 1081 | + assert res.automergeable |
| 1082 | + assert res.path is None |
| 1083 | + assert res.mode == hello_txt.mode |
| 1084 | + assert res.contents == testrepo.get(hello_txt.id).data.decode() |
| 1085 | + |
| 1086 | + # path switch on ours, executable flag switch on theirs |
| 1087 | + res = testrepo.merge_file_from_index(hello_txt, hello_world, hello_txt_executable, use_deprecated=False) |
| 1088 | + assert res.automergeable |
| 1089 | + assert res.path == hello_world.path |
| 1090 | + assert res.mode == hello_txt_executable.mode |
| 1091 | + assert res.contents == testrepo.get(hello_txt.id).data.decode() |
| 1092 | + |
| 1093 | + # path switch on theirs, executable flag switch on ours |
| 1094 | + res = testrepo.merge_file_from_index(hello_txt, hello_txt_executable, hello_world, use_deprecated=False) |
| 1095 | + assert res.automergeable |
| 1096 | + assert res.path == hello_world.path |
| 1097 | + assert res.mode == hello_txt_executable.mode |
| 1098 | + assert res.contents == testrepo.get(hello_txt.id).data.decode() |
0 commit comments