Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ jobs:
- uses: rustsec/audit-check@v1.4.1
with:
token: ${{ secrets.GITHUB_TOKEN }}
ignore: RUSTSEC-2024-0364

coverage:
name: Code Coverage
Expand Down
8 changes: 8 additions & 0 deletions audit.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# SPDX-FileCopyrightText: 2025 Adam Poulemanos <89049923+bashandbone@users.noreply.github.com>
#
# SPDX-License-Identifier: LicenseRef-PlainMIT OR MIT

[advisories]
ignore = [
"RUSTSEC-2024-0364", # gitoxide-core does not neutralize special characters for terminals. No patched version available.
]
1 change: 1 addition & 0 deletions deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ feature-depth = 1
# A list of advisory IDs to ignore. Note that ignored advisories will still
# output a note when they are encountered.
ignore = [
"RUSTSEC-2024-0364", # gitoxide-core does not neutralize special characters for terminals. No patched version available.
# "RUSTSEC-0000-0000",
# { id = "RUSTSEC-0000-0000", reason = "you can specify a reason the advisory is ignored" },
# "a-crate-that-is-yanked@0.1.1", # you can also ignore yanked crate versions if you wish
Expand Down
1 change: 0 additions & 1 deletion src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ pub enum Commands {
#[arg(short = 'u', long = "update", help = "How git should update the submodule when you run `git submodule update`.")]
update: Option<Update>,

// TODO: Implement this arg
#[arg(short = 's', long = "shallow", default_value = "false", action = clap::ArgAction::SetTrue, default_missing_value = "true", help = "If given, sets the submodule as a shallow clone. It will only fetch the last commit of the branch, not the full history.")]
shallow: bool,

Expand Down
58 changes: 29 additions & 29 deletions src/git_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,26 +403,26 @@ impl GitManager {
path: String,
url: String,
sparse_paths: Option<Vec<String>>,
_branch: Option<SerializableBranch>,
_ignore: Option<SerializableIgnore>,
_fetch: Option<SerializableFetchRecurse>,
_update: Option<SerializableUpdate>,
_shallow: Option<bool>,
_no_init: bool,
branch: Option<SerializableBranch>,
ignore: Option<SerializableIgnore>,
fetch: Option<SerializableFetchRecurse>,
update: Option<SerializableUpdate>,
shallow: Option<bool>,
no_init: bool,
) -> Result<(), SubmoduleError> {
if _no_init {
if no_init {
self.update_toml_config(
name.clone(),
SubmoduleEntry {
path: Some(path.clone()),
url: Some(url.clone()),
branch: _branch.clone(),
ignore: _ignore.clone(),
update: _update.clone(),
fetch_recurse: _fetch.clone(),
branch: branch.clone(),
ignore: ignore.clone(),
update: update.clone(),
fetch_recurse: fetch.clone(),
active: Some(true),
shallow: _shallow,
no_init: Some(_no_init),
shallow: shallow,
no_init: Some(no_init),
sparse_paths: None,
},
sparse_paths.clone(),
Expand All @@ -438,11 +438,11 @@ impl GitManager {
name: name.clone(),
path: std::path::PathBuf::from(&path),
url: url.clone(),
branch: None,
ignore: None,
update: None,
fetch_recurse: None,
shallow: false,
branch: branch.clone(),
ignore: ignore.clone(),
update: update.clone(),
fetch_recurse: fetch.clone(),
shallow: shallow.unwrap_or(false),
no_init: false,
};
match self.git_ops.add_submodule(&opts).map_err(Self::map_git_ops_error) {
Expand All @@ -454,13 +454,13 @@ impl GitManager {
SubmoduleEntry {
path: Some(path),
url: Some(url),
branch: _branch,
ignore: _ignore,
update: _update,
fetch_recurse: _fetch,
branch: branch,
ignore: ignore,
update: update,
fetch_recurse: fetch,
active: Some(true),
shallow: _shallow,
no_init: Some(_no_init),
shallow: shallow,
no_init: Some(no_init),
sparse_paths: None, // stored separately via configure_submodule_post_creation
},
sparse_paths,
Expand Down Expand Up @@ -699,11 +699,11 @@ impl GitManager {
name: name.to_string(),
path: std::path::PathBuf::from(path_str),
url: url_str.to_string(),
branch: None,
ignore: None,
update: None,
fetch_recurse: None,
shallow: false,
branch: config.branch.clone(),
ignore: config.ignore.clone(),
update: config.update.clone(),
fetch_recurse: config.fetch_recurse.clone(),
shallow: config.shallow.unwrap_or(false),
no_init: false,
};
self.git_ops.add_submodule(&opts)
Expand Down
43 changes: 43 additions & 0 deletions tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -751,4 +751,47 @@ active = true
let config = harness.read_config().expect("Failed to read config");
assert!(!config.contains("[nuke-lib]"));
}

#[test]
fn test_add_submodule_shallow() {
let harness = TestHarness::new().expect("Failed to create test harness");
harness.init_git_repo().expect("Failed to init git repo");

let remote_repo = harness
.create_test_remote("shallow_lib")
.expect("Failed to create remote");
let remote_url = format!("file://{}", remote_repo.display());

// Add submodule with shallow flag
let stdout = harness
.run_submod_success(&[
"add",
&remote_url,
"--name",
"shallow-lib",
"--path",
"lib/shallow",
"--shallow",
])
.expect("Failed to add submodule");

assert!(stdout.contains("Added submodule"));

// Verify config includes shallow = true
let config = harness.read_config().expect("Failed to read config");
assert!(config.contains("shallow = true"));

// Verify it is a shallow clone using git command
let output = std::process::Command::new("git")
.args(["rev-parse", "--is-shallow-repository"])
.current_dir(harness.work_dir.join("lib/shallow"))
.output()
.expect("Failed to run git");

let is_shallow = String::from_utf8_lossy(&output.stdout).trim();
assert_eq!(
is_shallow, "true",
"Repository at lib/shallow should be shallow"
);
}
}
Loading