Skip to content

Commit

Permalink
fix: remote tasks and devcontainer (#4557)
Browse files Browse the repository at this point in the history
- πŸ› Fix devcontainer parent folder creation
- πŸ› Fix remote tasks when using gix or libgit2
  • Loading branch information
acesyde authored Feb 28, 2025
1 parent 097660b commit 6ba5d3b
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 3 deletions.
32 changes: 32 additions & 0 deletions e2e/assert.sh
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,38 @@ assert_empty() {
fi
}

assert_directory_exists() {
if [[ -d "$1" ]]; then
ok "[$1] directory exists"
else
fail "[$1] directory does not exist"
fi
}

assert_directory_not_exists() {
if [[ ! -d "$1" ]]; then
ok "[$1] directory does not exist"
else
fail "[$1] directory exists"
fi
}

assert_directory_empty() {
if [[ -z "$(ls -A "$1")" ]]; then
ok "[$1] directory is empty"
else
fail "[$1] directory is not empty"
fi
}

assert_directory_not_empty() {
if [[ -n "$(ls -A "$1")" ]]; then
ok "[$1] directory is not empty"
else
fail "[$1] directory is empty"
fi
}

require_cmd() {
if ! type -p "$1" >/dev/null; then
title="E2E test $TEST_NAME aborted" err "'$1' is required but was not found in PATH"
Expand Down
31 changes: 31 additions & 0 deletions e2e/tasks/test_task_remote_git_https
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
#!/usr/bin/env bash

#################################################################################
# Setup
#################################################################################

REMOTE_TASKS_DIR="${MISE_CACHE_DIR}/remote-git-tasks-cache"
MISE_V2025117_CACHE_DIR="${REMOTE_TASKS_DIR}/791bacd406835a949d44cc2ac1106e0e4475d131ccc56b2540846d661bf5ff5c"

cargo init --name hello_cargo

#################################################################################
Expand All @@ -13,14 +20,26 @@ EOF

assert_contains "mise tasks" "remote_lint_https_latest"
assert_succeed "mise run remote_lint_https_latest" # Remote task should be downloaded
assert_directory_exists "${REMOTE_TASKS_DIR}"
assert_directory_not_empty "${REMOTE_TASKS_DIR}"
assert_directory_not_exists "${MISE_V2025117_CACHE_DIR}"

mise cache clear # Clear cache to force redownload

assert_succeed "MISE_TASK_REMOTE_NO_CACHE=true mise run remote_lint_https_latest" # Remote task should be redownloaded
assert_directory_not_exists "${REMOTE_TASKS_DIR}"
assert_directory_not_exists "${MISE_V2025117_CACHE_DIR}"

assert_succeed "mise run remote_lint_https_latest --no-cache" # Remote task should be redownloaded
assert_directory_not_exists "${REMOTE_TASKS_DIR}"
assert_directory_not_exists "${MISE_V2025117_CACHE_DIR}"

assert_succeed "mise run remote_lint_https_latest" # Cache should be used
assert_directory_exists "${REMOTE_TASKS_DIR}"
assert_directory_not_empty "${REMOTE_TASKS_DIR}"
assert_directory_not_exists "${MISE_V2025117_CACHE_DIR}"

mise cache clear # Clear cache to force redownload

#################################################################################
# Test remote tasks with with ref
Expand All @@ -33,11 +52,23 @@ EOF

assert_contains "mise tasks" "remote_lint_https_ref"
assert_succeed "mise run remote_lint_https_ref" # Remote task should be downloaded
assert_directory_exists "${REMOTE_TASKS_DIR}"
assert_directory_not_empty "${REMOTE_TASKS_DIR}"
assert_directory_exists "${MISE_V2025117_CACHE_DIR}"
assert_directory_not_empty "${MISE_V2025117_CACHE_DIR}"

mise cache clear # Clear cache to force redownload

assert_succeed "MISE_TASK_REMOTE_NO_CACHE=true mise run remote_lint_https_ref" # Remote task should be redownloaded
assert_directory_not_exists "${REMOTE_TASKS_DIR}"
assert_directory_not_exists "${MISE_V2025117_CACHE_DIR}"

assert_succeed "mise run remote_lint_https_ref --no-cache" # Remote task should be redownloaded
assert_directory_not_exists "${REMOTE_TASKS_DIR}"
assert_directory_not_exists "${MISE_V2025117_CACHE_DIR}"

assert_succeed "mise run remote_lint_https_ref" # Cache should be used
assert_directory_exists "${REMOTE_TASKS_DIR}"
assert_directory_not_empty "${REMOTE_TASKS_DIR}"
assert_directory_exists "${MISE_V2025117_CACHE_DIR}"
assert_directory_not_empty "${MISE_V2025117_CACHE_DIR}"
37 changes: 34 additions & 3 deletions e2e/tasks/test_task_remote_git_ssh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ if [ -n "$EXCLUDE_FROM_CI" ]; then
exit 0
fi

#################################################################################
# Setup
#################################################################################

REMOTE_TASKS_DIR="${MISE_CACHE_DIR}/remote-git-tasks-cache"
MISE_V2025117_CACHE_DIR="${REMOTE_TASKS_DIR}/2fc21c39bc011033ee92059b37f2e91f844600fbbf78434b2782900949056f7e"

cargo init --name hello_cargo

#################################################################################
Expand All @@ -18,18 +25,30 @@ EOF

assert_contains "mise tasks" "remote_lint_ssh_latest"
assert_succeed "mise run remote_lint_ssh_latest" # Remote task should be downloaded
assert_directory_exists "${REMOTE_TASKS_DIR}"
assert_directory_not_empty "${REMOTE_TASKS_DIR}"
assert_directory_not_exists "${MISE_V2025117_CACHE_DIR}"

mise cache clear # Clear cache to force redownload

assert_succeed "MISE_TASK_REMOTE_NO_CACHE=true mise run remote_lint_ssh_latest" # Remote task should be redownloaded
assert_directory_not_exists "${REMOTE_TASKS_DIR}"
assert_directory_not_exists "${MISE_V2025117_CACHE_DIR}"

assert_succeed "mise run remote_lint_ssh_latest --no-cache" # Remote task should be redownloaded
assert_directory_not_exists "${REMOTE_TASKS_DIR}"
assert_directory_not_exists "${MISE_V2025117_CACHE_DIR}"

assert_succeed "mise run remote_lint_ssh_latest" # Cache should be used
assert_directory_exists "${REMOTE_TASKS_DIR}"
assert_directory_not_empty "${REMOTE_TASKS_DIR}"
assert_directory_not_exists "${MISE_V2025117_CACHE_DIR}"

#################################################################################
# Test remote tasks with with ref
#################################################################################
mise cache clear # Clear cache to force redownload

# #################################################################################
# # Test remote tasks with with ref
# #################################################################################

cat <<EOF >mise.toml
[tasks.remote_lint_ssh_ref]
Expand All @@ -38,11 +57,23 @@ EOF

assert_contains "mise tasks" "remote_lint_ssh_ref"
assert_succeed "mise run remote_lint_ssh_ref" # Remote task should be downloaded
assert_directory_exists "${REMOTE_TASKS_DIR}"
assert_directory_not_empty "${REMOTE_TASKS_DIR}"
assert_directory_exists "${MISE_V2025117_CACHE_DIR}"
assert_directory_not_empty "${MISE_V2025117_CACHE_DIR}"

mise cache clear # Clear cache to force redownload

assert_succeed "MISE_TASK_REMOTE_NO_CACHE=true mise run remote_lint_ssh_ref" # Remote task should be redownloaded
assert_directory_not_exists "${REMOTE_TASKS_DIR}"
assert_directory_not_exists "${MISE_V2025117_CACHE_DIR}"

assert_succeed "mise run remote_lint_ssh_ref --no-cache" # Remote task should be redownloaded
assert_directory_not_exists "${REMOTE_TASKS_DIR}"
assert_directory_not_exists "${MISE_V2025117_CACHE_DIR}"

assert_succeed "mise run remote_lint_ssh_ref" # Cache should be used
assert_directory_exists "${REMOTE_TASKS_DIR}"
assert_directory_not_empty "${REMOTE_TASKS_DIR}"
assert_directory_exists "${MISE_V2025117_CACHE_DIR}"
assert_directory_not_empty "${MISE_V2025117_CACHE_DIR}"
1 change: 1 addition & 0 deletions src/cli/generate/devcontainer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ impl Devcontainer {

if self.write {
let path = Git::get_root()?.join(".devcontainer/devcontainer.json");
file::create(&path)?;
file::write(&path, &output)?;
miseprintln!("Wrote to {}", display_path(&path));
} else {
Expand Down
5 changes: 5 additions & 0 deletions src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,13 @@ impl Git {
file::mkdirp(parent)?;
}
if SETTINGS.libgit2 || SETTINGS.gix {
debug!("Use libgit2 or gix");
let mut prepare_clone = gix::prepare_clone(url, &self.dir)?;

if let Some(branch) = &options.branch {
prepare_clone = prepare_clone.with_ref_name(Some(branch))?;
}

let (mut prepare_checkout, _) = prepare_clone
.fetch_then_checkout(gix::progress::Discard, &gix::interrupt::IS_INTERRUPTED)?;

Expand Down
1 change: 1 addition & 0 deletions src/task/task_file_providers/remote_task_git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ impl TaskFileProvider for RemoteTaskGit {
let mut clone_options = CloneOptions::default();

if let Some(branch) = &repo_structure.branch {
trace!("Use specific branch {}", branch);
clone_options = clone_options.branch(branch);
}

Expand Down

0 comments on commit 6ba5d3b

Please sign in to comment.