Skip to content

Commit 6d61128

Browse files
committed
Repair Git state comment formatting
The _uptodate() function already invokes _format_comments() on the comments passed, avoid duplicate invocations of _format_comments() which caused the joined string result from being joined with dots a second time, effectively placing a dot after every character in the resulting comment output. Also amend the test suite to cover these output conditions. Signed-off-by: Georg Pfuetzenreuter <mail@georg-pfuetzenreuter.net>
1 parent 21e99f6 commit 6d61128

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

changelog/67944.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Repair Git state comment formatting

salt/states/git.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -949,9 +949,7 @@ def latest(
949949
target,
950950
force_reset,
951951
)
952-
return _uptodate(
953-
ret, target, _format_comments(comments), local_changes
954-
)
952+
return _uptodate(ret, target, comments, local_changes)
955953

956954
if (
957955
remote_rev_type == "sha1"
@@ -1181,7 +1179,7 @@ def latest(
11811179
# user of the actions taken.
11821180
ret["comment"] = _format_comments(actions)
11831181
return ret
1184-
return _uptodate(ret, target, _format_comments(actions))
1182+
return _uptodate(ret, target, actions)
11851183

11861184
# The fetch_url for the desired remote does not match the
11871185
# specified URL (or the remote does not exist), so set the
@@ -1291,7 +1289,7 @@ def latest(
12911289
if not revs_match and not update_head and formatted_actions:
12921290
ret["comment"] = formatted_actions
12931291
return ret
1294-
return _uptodate(ret, target, _format_comments(actions))
1292+
return _uptodate(ret, target, actions)
12951293

12961294
if not upstream and desired_upstream:
12971295
upstream_action = "Tracking branch was set to {}".format(
@@ -1685,7 +1683,7 @@ def latest(
16851683
ret["comment"] = _format_comments(comments)
16861684
ret["changes"]["revision"] = {"old": local_rev, "new": new_rev}
16871685
else:
1688-
return _uptodate(ret, target, _format_comments(comments))
1686+
return _uptodate(ret, target, comments)
16891687
else:
16901688
if os.path.isdir(target):
16911689
target_contents = os.listdir(target)

tests/integration/states/test_git.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,17 @@ def test_latest_with_local_changes(self, target):
295295
"git.latest", name=TEST_REPO, target=target, force_reset=True
296296
)
297297
self.assertSaltTrueReturn(ret)
298+
ret = ret[next(iter(ret))]
299+
# beginning of comment
300+
self.assertEqual(
301+
f"Repository {target} is up-to-date\n",
302+
ret["comment"][0 : 26 + len(target)],
303+
)
304+
self.assertIn("Uncommitted changes were discarded.", ret["comment"])
305+
# ending of comment
306+
self.assertEqual(
307+
"Repository was hard-reset to remote HEAD (bbefe81).", ret["comment"][-51:]
308+
)
298309

299310
# Make sure that we no longer have uncommitted changes
300311
self.assertFalse(self.run_function("git.diff", [target, "HEAD"]))

0 commit comments

Comments
 (0)