Skip to content

Commit 05bcaf3

Browse files
CopilotbashandboneCopilot
authored
fix: SPDX headers in CLAUDE.md; delegate SerializableBranch deserialization to from_gitmodules (#36)
* Initial plan * fix: add SPDX headers to CLAUDE.md; delegate SerializableBranch deserialization to from_gitmodules Co-authored-by: bashandbone <89049923+bashandbone@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: bashandbone <89049923+bashandbone@users.noreply.github.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent 25b424e commit 05bcaf3

2 files changed

Lines changed: 43 additions & 5 deletions

File tree

CLAUDE.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
<!--
2+
SPDX-FileCopyrightText: 2025 Adam Poulemanos <89049923+bashandbone@users.noreply.github.com>
3+
4+
SPDX-License-Identifier: LicenseRef-PlainMIT OR MIT
5+
-->
6+
17
# CLAUDE.md
28

39
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

src/options.rs

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -402,13 +402,14 @@ impl Serialize for SerializableBranch {
402402
}
403403

404404
impl<'de> Deserialize<'de> for SerializableBranch {
405-
/// Deserialize from a plain string using the same logic as [`FromStr`].
405+
/// Deserialize from a plain string, delegating to [`from_gitmodules`](GitmodulesConvert::from_gitmodules).
406406
/// Accepts `"."`, `"current"`, `"current-in-super-project"`, `"superproject"`, or `"super"`
407-
/// as [`CurrentInSuperproject`](SerializableBranch::CurrentInSuperproject); all other strings
408-
/// become [`Name`](SerializableBranch::Name).
407+
/// as [`CurrentInSuperproject`](SerializableBranch::CurrentInSuperproject); all other
408+
/// non-empty, non-whitespace strings become [`Name`](SerializableBranch::Name).
409+
/// Empty or whitespace-only strings are rejected with a deserialization error.
409410
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
410411
let s = String::deserialize(deserializer)?;
411-
SerializableBranch::from_str(&s)
412+
SerializableBranch::from_gitmodules(&s)
412413
.map_err(|_| serde::de::Error::custom(format!("invalid branch value: {s}")))
413414
}
414415
}
@@ -446,7 +447,10 @@ impl GitmodulesConvert for SerializableBranch {
446447
|| options == "current-in-super-project"
447448
|| options == "superproject"
448449
|| options == "super"
449-
|| options == SerializableBranch::current_in_superproject().unwrap_or_default()
450+
|| SerializableBranch::current_in_superproject()
451+
.ok()
452+
.as_deref()
453+
.map_or(false, |cur| cur == options)
450454
{
451455
return Ok(SerializableBranch::CurrentInSuperproject);
452456
}
@@ -464,6 +468,34 @@ impl GitmodulesConvert for SerializableBranch {
464468
}
465469
}
466470

471+
#[cfg(test)]
472+
mod tests {
473+
use super::SerializableBranch;
474+
475+
#[test]
476+
fn test_branch_deserialize_from_toml_rejects_empty_and_whitespace() {
477+
// Empty string should be rejected
478+
let res_empty: Result<SerializableBranch, toml::de::Error> =
479+
toml::from_str(r#"branch = """"#);
480+
assert!(res_empty.is_err(), "expected error for empty branch value");
481+
let err_empty = res_empty.unwrap_err().to_string();
482+
assert!(
483+
err_empty.contains("invalid branch value"),
484+
"error for empty branch value should contain context, got: {err_empty}"
485+
);
486+
487+
// Whitespace-only string should be rejected
488+
let res_ws: Result<SerializableBranch, toml::de::Error> =
489+
toml::from_str(r#"branch = " ""#);
490+
assert!(res_ws.is_err(), "expected error for whitespace-only branch value");
491+
let err_ws = res_ws.unwrap_err().to_string();
492+
assert!(
493+
err_ws.contains("invalid branch value"),
494+
"error for whitespace-only branch value should contain context, got: {err_ws}"
495+
);
496+
}
497+
}
498+
467499
impl TryFrom<Branch> for SerializableBranch {
468500
type Error = ();
469501

0 commit comments

Comments
 (0)