Skip to content

Commit

Permalink
fix removing a non-existant file
Browse files Browse the repository at this point in the history
  • Loading branch information
gschoeni committed Dec 5, 2024
1 parent fc41f5e commit 81f6539
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 24 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ cli-test/.rspec_status
# Ignore data in fixtures, retain script to generate fixtures through cloning
cli-test/spec/fixtures/*
!cli-test/spec/fixtures/create_fixtures.sh
cli-test/vendor/

# Per-project Cargo config
# We're currently only using this for configuring mold/sold for local
Expand Down
27 changes: 27 additions & 0 deletions cli-test/spec/test_cases/rm/tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,31 @@
expect(File.exist?(File.join(directory_path, 'root.txt'))).to be false
expect(File.exist?(File.join(directory_path, 'images/test/nested.txt'))).to be false
end

it 'tests oxen rm with removed path from disk' do
directory_path = 'tmp/aruba/test-removed-path'

# Setup base repo
run_command_and_stop('mkdir test-removed-path')
cd 'test-removed-path'
run_command_and_stop('oxen init')

# Create and commit root file
file_path = File.join(directory_path, 'root.txt')
File.open(file_path, 'w') do |file|
file.puts 'root file'
end
run_command_and_stop('oxen add root.txt')
run_command_and_stop('oxen commit -m "adding root file"')

# Test removing file before running oxen rm
run_command_and_stop('rm root.txt')
run_command_and_stop('oxen rm root.txt')

# Should show files as removed in staging
expect(last_command_started).to have_output(/removed 1 file/)

# Files should not exist on disk
expect(File.exist?(File.join(directory_path, 'root.txt'))).to be false
end
end
13 changes: 1 addition & 12 deletions src/cli/src/cmd/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,7 @@ impl RunCmd for AddCmd {
OxenError::basic_str(format!("Failed to get current directory: {}", e))
})?;
let joined_path = current_dir.join(p);
joined_path.canonicalize().map_err(|e| {
log::warn!(
"Failed to canonicalize path {}: {}",
joined_path.display(),
e
);
OxenError::basic_str(format!(
"Failed to canonicalize path {}: {}",
joined_path.display(),
e
))
})
joined_path.canonicalize().or_else(|_| Ok(joined_path))
})
.collect::<Result<Vec<PathBuf>, OxenError>>()?;

Expand Down
13 changes: 1 addition & 12 deletions src/cli/src/cmd/rm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,7 @@ impl RunCmd for RmCmd {
OxenError::basic_str(format!("Failed to get current directory: {}", e))
})?;
let joined_path = current_dir.join(p);
joined_path.canonicalize().map_err(|e| {
log::warn!(
"Failed to canonicalize path {}: {}",
joined_path.display(),
e
);
OxenError::basic_str(format!(
"Failed to canonicalize path {}: {}",
joined_path.display(),
e
))
})
joined_path.canonicalize().or_else(|_| Ok(joined_path))
})
.collect::<Result<Vec<PathBuf>, OxenError>>()?;

Expand Down

0 comments on commit 81f6539

Please sign in to comment.