Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: avoid copying gitignored files (#1000) #1001

Merged
merged 8 commits into from
Sep 30, 2023
9 changes: 4 additions & 5 deletions crates/release_plz_core/src/copy_dir.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::{fs, io, path::Path};

use anyhow::Context;
use ignore::{DirEntry, WalkBuilder};
use tracing::debug;
use walkdir::WalkDir;

use crate::strip_prefix::strip_prefix;

Expand Down Expand Up @@ -46,11 +46,10 @@ pub fn copy_dir(from: impl AsRef<Path>, to: impl AsRef<Path>) -> anyhow::Result<
#[tracing::instrument]
#[allow(clippy::filetype_is_file)] // we want to distinguish between files and symlinks
fn copy_directory(from: &Path, to: std::path::PathBuf) -> Result<(), anyhow::Error> {
for entry in WalkDir::new(from) {
for entry in WalkBuilder::new(from).hidden(false).ignore(true).build() {
let entry = entry.context("invalid entry")?;
let destination = destination_path(&to, &entry, from)?;

let file_type = entry.file_type();
let file_type = entry.file_type().context("unknown file type")?;
if file_type.is_dir() {
if destination == to {
continue;
Expand Down Expand Up @@ -86,7 +85,7 @@ fn copy_directory(from: &Path, to: std::path::PathBuf) -> Result<(), anyhow::Err

fn destination_path(
to: &Path,
entry: &walkdir::DirEntry,
entry: &DirEntry,
from: &Path,
) -> anyhow::Result<std::path::PathBuf> {
let mut dest_path = to.to_path_buf();
Expand Down