GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitPython/test/test_fun.py at main · gitpython-developers/GitPython

Expand file tree

/

test_fun.py

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
143 lines (124 loc) · 5.56 KB
/

test_fun.py

Copy path

File metadata and controls

143 lines (124 loc) · 5.56 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# This module is part of GitPython and is released under the
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/
from io import BytesIO
from os import stat
from stat import S_IFDIR, S_IFLNK, S_IFREG, S_IXUSR
from pathlib import Path
import ddt
from gitdb.base import IStream
from git.index import IndexFile
from git.index.fun import stat_mode_to_index_mode
from git.objects import Tree
from git.repo.fun import find_worktree_git_dir
from git.util import bin_to_hex
from test.lib import TestBase, with_rw_repo
from test.lib.fixtures import fixture_repo, read_only_fixture
@ddt.ddt
class TestFun(TestBase):
@staticmethod
def merge_trees(repo, trees):
return list(IndexFile.new(repo, *(tree.hex() for tree in trees)).iter_entries())
def _assert_index_entries(self, entries, trees):
index = IndexFile.from_tree(self.rorepo, *[self.rorepo.tree(bin_to_hex(t).decode("ascii")) for t in trees])
assert entries
assert len([(e.path, e.stage) for e in index.iter_entries()]) == len(entries)
for entry in entries:
assert (entry.path, entry.stage) in [(e.path, e.stage) for e in index.iter_entries()]
# END assert entry matches fully
def test_aggressive_tree_merge(self):
# Trees with additions, removals and modifications, including a submodule.
repo = self.rorepo
H = repo.tree("submodule-current")
B = repo.tree("side")
# Entries from single tree.
trees = [H.binsha]
self._assert_index_entries(self.merge_trees(repo, trees), trees)
# From multiple trees.
trees = [B.binsha, H.binsha]
self._assert_index_entries(self.merge_trees(repo, trees), trees)
# Three way, no conflict.
tree = self.rorepo.tree
B = tree("manifest-update")
H = tree("merge^1")
M = tree("side")
trees = [B.binsha, H.binsha, M.binsha]
self._assert_index_entries(self.merge_trees(repo, trees), trees)
# Three-way, conflict in at least one file, both modified.
B = tree("base")
H = tree("conflict-ours")
M = tree("conflict-theirs")
trees = [B.binsha, H.binsha, M.binsha]
self._assert_index_entries(self.merge_trees(repo, trees), trees)
# Too many trees.
self.assertRaises(ValueError, self.merge_trees, repo, trees * 2)
def test_three_way_merge(self):
def assert_entries(entries, num_entries, has_conflict=False):
assert len(entries) == num_entries
assert has_conflict == any(e.stage != 0 for e in entries)
with fixture_repo("fun.sh", "merge-trees", write=True) as repo:
root = Path(repo.working_tree_dir).parent
trees = {path.name: bytes.fromhex(path.read_text().strip()) for path in root.iterdir() if path.is_file()}
base = trees["base"]
for ours, theirs, count, conflict in (
("add-ours", "add-theirs", 3, False),
("only-ours", "only-theirs", 2, False),
("only-ours", "same-name-theirs", 2, True),
("only-ours", "gitlink-one", 2, True),
("only-ours", "only-ours", 1, False),
("modify-ours", "modify-theirs", 3, True),
("gitlink-base", "executable-base", 3, True),
):
assert_entries(self.merge_trees(repo, [base, trees[ours], trees[theirs]]), count, conflict)
for is_them in range(2):
for changed, oid, mode in (
("modify-ours", b"\2" * 20, S_IFREG | 0o644),
("gitlink-base", b"\1" * 20, S_IFDIR | S_IFLNK),
):
sides = [trees[changed], base]
if is_them:
sides.reverse()
entries = self.merge_trees(repo, [base, *sides])
assert len(entries) == 1 and entries[0].binsha == oid and entries[0].mode == mode
sides = [trees["modify-ours"], trees["empty"]]
if is_them:
sides.reverse()
assert_entries(self.merge_trees(repo, [base, *sides]), 2, True)
# END handle ours, theirs
def test_stat_mode_to_index_mode(self):
modes = (
0o600,
0o611,
0o640,
0o641,
0o644,
0o650,
0o651,
0o700,
0o711,
0o740,
0o744,
0o750,
0o751,
0o755,
)
for mode in modes:
expected_mode = S_IFREG | (mode & S_IXUSR and 0o755 or 0o644)
assert stat_mode_to_index_mode(mode) == expected_mode
# END for each mode
def test_linked_worktree_traversal(self):
"""Identify a linked worktree from an immutable scripted .git file."""
root = read_only_fixture("fun.sh", "worktree", self.rorepo.working_dir, self.rorepo.head.commit.hexsha)
dotgit = root / "worktree_repo/.git"
self.assertTrue(stat(dotgit).st_mode & S_IFREG)
gitdir = find_worktree_git_dir(dotgit)
self.assertIsNotNone(gitdir)
self.assertTrue(stat(gitdir).st_mode & S_IFDIR)
@with_rw_repo("release")
def test_tree_names_from_git_preserve_undecodable_bytes(self, repo):
tree = Tree(repo, repo._null_binsha, path="")
tree._cache = [(b"a" * repo._oid_size, 0o100644, "\udc9f")]
data = BytesIO()
tree._serialize(data)
data.seek(0)
stored = repo.odb.store(IStream("tree", len(data.getvalue()), data))
assert Tree(repo, stored.binsha, path="")._cache == tree._cache
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.