Skip to content

Commit 135e2bc

Browse files
committed
feat: register the local repo for shell and run by default
Traditionally, only `build` allows oma to use the local repo. This patch ports this feature to `shell` and `run` for a better debugging experience.
1 parent 860c955 commit 135e2bc

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

src/actions/container.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::{
1616
config, error, info,
1717
machine::{self, get_container_ns_name, inspect_instance, spawn_container},
1818
network::download_file_progress,
19-
overlayfs, warn,
19+
overlayfs, repo, warn,
2020
};
2121

2222
use super::{for_each_instance, APT_UPDATE_SCRIPT};
@@ -298,6 +298,28 @@ pub fn start_container(instance: &str) -> Result<String> {
298298
Ok(ns_name)
299299
}
300300

301+
/// Prepare the local repository for the container
302+
pub fn prepare_local_repo(instance: &str) -> Result<()> {
303+
let conf = config::read_config();
304+
if conf.is_err() {
305+
return Err(anyhow!("Please configure this workspace first!"));
306+
}
307+
let conf = conf.unwrap();
308+
if !conf.local_repo {
309+
return Err(anyhow!("Please enable local packages repository first!"));
310+
}
311+
let ns_name = get_instance_ns_name(instance)?;
312+
let inst = inspect_instance(instance, &ns_name)?;
313+
let output_dir = get_output_directory(conf.sep_mount);
314+
let root = std::env::current_dir()?.join(output_dir);
315+
if !inst.mounted {
316+
mount_fs(instance)?;
317+
}
318+
info!("Refreshing local repository...");
319+
repo::init_repo(root.as_ref(), Path::new(&instance))?;
320+
Ok(())
321+
}
322+
301323
/// Execute the specified command in the container
302324
pub fn run_in_container<S: AsRef<OsStr>>(instance: &str, args: &[S]) -> Result<i32> {
303325
let ns_name = start_container(instance)?;

src/cli.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,29 @@ pub fn build_cli() -> Command {
9191
Command::new("shell")
9292
.alias("sh")
9393
.arg(instance_arg.clone().help("Instance to be used"))
94+
.arg(
95+
Arg::new("NO_LOCAL_REPO")
96+
.long("no-local-repo")
97+
.action(clap::ArgAction::SetTrue)
98+
.help(
99+
"Avoid preparing the local repository for the interactive environment",
100+
),
101+
)
94102
.arg(Arg::new("COMMANDS").required(false).num_args(1..))
95103
.about("Start an interactive shell"),
96104
)
97105
.subcommand(
98106
Command::new("run")
99107
.alias("exec")
100108
.arg(instance_arg.clone().help("Instance to run command in"))
109+
.arg(
110+
Arg::new("NO_LOCAL_REPO")
111+
.long("no-local-repo")
112+
.action(clap::ArgAction::SetTrue)
113+
.help(
114+
"Avoid preparing the local repository for the interactive environment",
115+
),
116+
)
101117
.arg(Arg::new("COMMANDS").required(true).num_args(1..))
102118
.about("Lower-level version of 'shell', without login environment, without sourcing ~/.bash_profile"),
103119
)

src/main.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,13 +278,19 @@ fn main() -> Result<()> {
278278
}
279279
("run", args) => {
280280
let instance = get_instance_option(args)?;
281+
if !args.get_flag("NO_LOCAL_REPO") {
282+
actions::prepare_local_repo(&instance)?;
283+
}
281284
let args = args.get_many::<String>("COMMANDS").unwrap();
282285
let status =
283286
actions::run_in_container(&instance, &args.into_iter().collect::<Vec<_>>())?;
284287
process::exit(status);
285288
}
286289
("shell", args) => {
287290
let instance = get_instance_option(args)?;
291+
if !args.get_flag("NO_LOCAL_REPO") {
292+
actions::prepare_local_repo(&instance)?;
293+
}
288294
if let Some(cmd) = args.get_many::<String>("COMMANDS") {
289295
let command = cmd
290296
.into_iter()

0 commit comments

Comments
 (0)