Skip to content

Commit f08318c

Browse files
authored
Merge pull request #11036 from gitbutlerapp/copilot/fix-notification-badge-issue
Fix `but --json status` to serialize paths as strings instead of byte arrays
2 parents edef902 + 92ebfdd commit f08318c

File tree

4 files changed

+205
-0
lines changed

4 files changed

+205
-0
lines changed

crates/but/src/status/assignment.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use but_hunk_assignment::HunkAssignment;
33

44
#[derive(Debug, Clone, serde::Serialize)]
55
pub(crate) struct FileAssignment {
6+
#[serde(with = "gitbutler_serde::bstring_lossy")]
67
pub path: BString,
78
pub assignments: Vec<HunkAssignment>,
89
}

crates/but/tests/but/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
mod commit;
22
mod journey;
3+
mod status;
34
pub mod utils;

crates/but/tests/but/status.rs

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
use crate::utils::Sandbox;
2+
use crate::utils::setup_metadata;
3+
4+
#[test]
5+
fn json_shows_paths_as_strings() -> anyhow::Result<()> {
6+
let env = Sandbox::init_scenario_with_target("two-stacks")?;
7+
8+
// Must set metadata to match the scenario, or else the old APIs used here won't deliver.
9+
setup_metadata(&env, &["A", "B"])?;
10+
11+
// Create a new file to ensure we have file assignments
12+
env.file("test-file.txt", "test content");
13+
14+
env
15+
.but("--json status")
16+
.with_assert(env.assert_with_uuid_and_timestamp_redactions())
17+
.assert()
18+
.success()
19+
.stderr_eq(snapbox::str![])
20+
.stdout_eq(snapbox::str![[r#"
21+
{
22+
"stacks": [
23+
[
24+
null,
25+
[
26+
null,
27+
[
28+
{
29+
"path": "test-file.txt",
30+
"assignments": [
31+
{
32+
"id": "[UUID]",
33+
"hunkHeader": {
34+
"oldStart": 1,
35+
"oldLines": 0,
36+
"newStart": 1,
37+
"newLines": 1
38+
},
39+
"path": "test-file.txt",
40+
"pathBytes": [
41+
116,
42+
101,
43+
115,
44+
116,
45+
45,
46+
102,
47+
105,
48+
108,
49+
101,
50+
46,
51+
116,
52+
120,
53+
116
54+
],
55+
"stackId": null,
56+
"lineNumsAdded": [
57+
1
58+
],
59+
"lineNumsRemoved": []
60+
}
61+
]
62+
}
63+
]
64+
]
65+
],
66+
[
67+
"[UUID]",
68+
[
69+
{
70+
"derivedName": "A",
71+
"pushStatus": "completelyUnpushed",
72+
"branchDetails": [
73+
{
74+
"name": "A",
75+
"remoteTrackingBranch": null,
76+
"description": null,
77+
"prNumber": null,
78+
"reviewId": null,
79+
"tip": "9477ae721ab521d9d0174f70e804ce3ff9f6fb56",
80+
"baseCommit": "0dc37334a458df421bf67ea806103bf5004845dd",
81+
"pushStatus": "completelyUnpushed",
82+
"lastUpdatedAt": [TIMESTAMP],
83+
"authors": [
84+
{
85+
"name": "author",
86+
"email": "[email protected]",
87+
"gravatarUrl": "https://www.gravatar.com/avatar/5c1e6d6e64e12aca17657581a48005d1?s=100&r=g&d=retro"
88+
}
89+
],
90+
"isConflicted": false,
91+
"commits": [
92+
{
93+
"id": "9477ae721ab521d9d0174f70e804ce3ff9f6fb56",
94+
"parentIds": [
95+
"0dc37334a458df421bf67ea806103bf5004845dd"
96+
],
97+
"message": "add A/n",
98+
"hasConflicts": false,
99+
"state": {
100+
"type": "LocalOnly"
101+
},
102+
"createdAt": 946684800000,
103+
"author": {
104+
"name": "author",
105+
"email": "[email protected]",
106+
"gravatarUrl": "https://www.gravatar.com/avatar/5c1e6d6e64e12aca17657581a48005d1?s=100&r=g&d=retro"
107+
},
108+
"gerritReviewUrl": null
109+
}
110+
],
111+
"upstreamCommits": [],
112+
"isRemoteHead": false
113+
}
114+
],
115+
"isConflicted": false
116+
},
117+
[]
118+
]
119+
],
120+
[
121+
"[UUID]",
122+
[
123+
{
124+
"derivedName": "B",
125+
"pushStatus": "completelyUnpushed",
126+
"branchDetails": [
127+
{
128+
"name": "B",
129+
"remoteTrackingBranch": null,
130+
"description": null,
131+
"prNumber": null,
132+
"reviewId": null,
133+
"tip": "d3e2ba36c529fbdce8de90593e22aceae21f9b17",
134+
"baseCommit": "0dc37334a458df421bf67ea806103bf5004845dd",
135+
"pushStatus": "completelyUnpushed",
136+
"lastUpdatedAt": [TIMESTAMP],
137+
"authors": [
138+
{
139+
"name": "author",
140+
"email": "[email protected]",
141+
"gravatarUrl": "https://www.gravatar.com/avatar/5c1e6d6e64e12aca17657581a48005d1?s=100&r=g&d=retro"
142+
}
143+
],
144+
"isConflicted": false,
145+
"commits": [
146+
{
147+
"id": "d3e2ba36c529fbdce8de90593e22aceae21f9b17",
148+
"parentIds": [
149+
"0dc37334a458df421bf67ea806103bf5004845dd"
150+
],
151+
"message": "add B/n",
152+
"hasConflicts": false,
153+
"state": {
154+
"type": "LocalOnly"
155+
},
156+
"createdAt": 946684800000,
157+
"author": {
158+
"name": "author",
159+
"email": "[email protected]",
160+
"gravatarUrl": "https://www.gravatar.com/avatar/5c1e6d6e64e12aca17657581a48005d1?s=100&r=g&d=retro"
161+
},
162+
"gerritReviewUrl": null
163+
}
164+
],
165+
"upstreamCommits": [],
166+
"isRemoteHead": false
167+
}
168+
],
169+
"isConflicted": false
170+
},
171+
[]
172+
]
173+
]
174+
],
175+
"common_merge_base": {
176+
"target_name": "origin/main",
177+
"common_merge_base": "0dc3733",
178+
"message": "add M "
179+
}
180+
}
181+
182+
"#]]);
183+
184+
Ok(())
185+
}

crates/but/tests/but/utils.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,24 @@ impl Sandbox {
104104
.action_env("SNAPSHOTS")
105105
.redact_with(redactions)
106106
}
107+
108+
/// Create an assert with custom redactions. Adapt as needed.
109+
pub fn assert_with_uuid_and_timestamp_redactions(&self) -> Assert {
110+
let mut redactions = Redactions::new();
111+
redactions
112+
.insert(
113+
"[UUID]",
114+
regex::Regex::new(r#"[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}"#).unwrap(),
115+
)
116+
.unwrap();
117+
redactions
118+
.insert("[TIMESTAMP]", regex::Regex::new(r#"[1-9]\d{12}"#).unwrap())
119+
.unwrap();
120+
Assert::new()
121+
.action_env("SNAPSHOTS")
122+
.redact_with(redactions)
123+
}
124+
107125
/// Print the paths to our directories, and keep them.
108126
pub fn debug(mut self) -> ! {
109127
eprintln!(

0 commit comments

Comments
 (0)