Skip to content

Commit

Permalink
make clear that we are currently only dealing with checkout during cl…
Browse files Browse the repository at this point in the history
…one (#301)
  • Loading branch information
Byron committed Feb 28, 2022
1 parent b14ac1e commit 3556af4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
7 changes: 7 additions & 0 deletions git-worktree/src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ pub mod checkout {
pub struct Options {
/// capabilities of the file system
pub fs: crate::fs::Context,
/// If true, we assume no file to exist in the target directory, and want exclusive access to it.
/// This should be enabled when cloning.
pub destination_is_initially_empty: bool,
}

quick_error! {
Expand Down Expand Up @@ -42,6 +45,9 @@ pub fn checkout<Find>(
where
Find: for<'a> FnMut(&oid, &'a mut Vec<u8>) -> Option<git_object::BlobRef<'a>>,
{
if !options.destination_is_initially_empty {
todo!("non-clone logic isn't implemented or vetted yet");
}
let root = path.as_ref();
let mut buf = Vec::new();
for (entry, entry_path) in index.entries_mut_with_paths() {
Expand Down Expand Up @@ -76,6 +82,7 @@ pub(crate) mod entry {
root: &std::path::Path,
index::checkout::Options {
fs: crate::fs::Context { symlink, .. },
..
}: index::checkout::Options,
buf: &mut Vec<u8>,
) -> Result<(), index::checkout::Error>
Expand Down
23 changes: 12 additions & 11 deletions git-worktree/tests/index/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,33 @@ mod checkout {
use git_object::bstr::ByteSlice;
use git_odb::FindExt;
use git_worktree::index;
use git_worktree::index::checkout::Options;
use tempfile::TempDir;

use crate::fixture_path;

#[test]
fn allow_symlinks() -> crate::Result {
let opts = index::checkout::Options {
fs: git_worktree::fs::Context {
symlink: true,
..Default::default()
},
};
let opts = opts_with_symlink(true);
let (source_tree, destination) = setup_fixture_with_options(opts, "make_mixed_without_submodules")?;

assert_equality(&source_tree, &destination, opts.fs.symlink)?;
Ok(())
}

#[test]
fn symlinks_become_files_if_disabled() -> crate::Result {
let opts = index::checkout::Options {
fn opts_with_symlink(symlink: bool) -> Options {
index::checkout::Options {
fs: git_worktree::fs::Context {
symlink: false,
symlink,
..Default::default()
},
};
destination_is_initially_empty: true,
}
}

#[test]
fn symlinks_become_files_if_disabled() -> crate::Result {
let opts = opts_with_symlink(false);
let (source_tree, destination) = setup_fixture_with_options(opts, "make_mixed_without_submodules")?;

assert_equality(&source_tree, &destination, opts.fs.symlink)?;
Expand Down

0 comments on commit 3556af4

Please sign in to comment.