Skip to content

Commit e60abda

Browse files
cmcmarrowMegan Wilhite
authored and
Megan Wilhite
committed
stop branch collision
1 parent dff6f6c commit e60abda

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

salt/utils/gitfs.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -458,14 +458,22 @@ def __init__(
458458
failhard(self.role)
459459

460460
hash_type = getattr(hashlib, self.opts.get("hash_type", "md5"))
461-
# Generate full id. The full id is made from these parts name-id-env-_root.
461+
# Generate full id.
462462
# Full id helps decrease the chances of collections in the gitfs cache.
463+
try:
464+
target = str(self.get_checkout_target())
465+
except AttributeError:
466+
target = ""
463467
self._full_id = "-".join(
464468
[
465469
getattr(self, "name", ""),
466-
self.id.replace(" ", "-"),
470+
self.id,
467471
getattr(self, "env", ""),
468472
getattr(self, "_root", ""),
473+
self.role,
474+
getattr(self, "base", ""),
475+
getattr(self, "branch", ""),
476+
target
469477
]
470478
)
471479
# We loaded this data from yaml configuration files, so, its safe

tests/pytests/unit/utils/test_gitfs.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import time
44

55
import pytest
6+
67
import salt.config
78
import salt.fileserver.gitfs
89
import salt.utils.gitfs
@@ -245,7 +246,7 @@ def test_checkout_pygit2(_prepare_provider):
245246
)
246247
def test_full_id_pygit2(_prepare_provider):
247248
assert _prepare_provider.full_id().startswith("-")
248-
assert _prepare_provider.full_id().endswith("/pygit2-repo--")
249+
assert _prepare_provider.full_id().endswith("/pygit2-repo---gitfs-master--")
249250

250251

251252
@pytest.mark.skipif(not HAS_PYGIT2, reason="This host lacks proper pygit2 support")

tests/unit/utils/test_gitfs.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import tempfile
77

88
import pytest
9+
910
import salt.ext.tornado.ioloop
1011
import salt.fileserver.gitfs
1112
import salt.utils.files
@@ -114,23 +115,23 @@ def test_update_by_id_and_name(self):
114115
self.assertFalse(self.main_class.remotes[1].fetched)
115116

116117
def test_full_id(self):
117-
self.assertEqual(self.main_class.remotes[0].full_id(), "-file://repo1.git--")
118+
self.assertEqual(self.main_class.remotes[0].full_id(), "-file://repo1.git---gitfs-master--")
118119

119120
def test_full_id_with_name(self):
120121
self.assertEqual(
121-
self.main_class.remotes[1].full_id(), "repo2-file://repo2.git--"
122+
self.main_class.remotes[1].full_id(), "repo2-file://repo2.git---gitfs-master--"
122123
)
123124

124125
def test_get_cachedir_basename(self):
125126
self.assertEqual(
126127
self.main_class.remotes[0].get_cachedir_basename(),
127-
"-tNy9UbCHQuwj6vltGS0ptBfsE36nygwN4lFc+vbiaGA=",
128+
"-jXhnbGDemchtZwTwaD2s6VOaVvs98a7w+AtiYlmOVb0=",
128129
)
129130

130131
def test_get_cachedir_base_with_name(self):
131132
self.assertEqual(
132133
self.main_class.remotes[1].get_cachedir_basename(),
133-
"repo2-QhjC+OMDxuokzFQdh0jlI9W0Q8MFAXCkOhoAviU7Vqo=",
134+
"repo2-nuezpiDtjQRFC0ZJDByvi+F6Vb8ZhfoH41n_KFxTGsU=",
134135
)
135136

136137
def test_git_provider_mp_lock(self):

0 commit comments

Comments
 (0)