Skip to content

Commit

Permalink
feat: avoid copying gitignored files (#1000)
Browse files Browse the repository at this point in the history
  • Loading branch information
orhun committed Sep 29, 2023
1 parent a9f624f commit 5e80351
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions crates/release_plz_core/src/copy_dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::{fs, io, path::Path};

use anyhow::Context;
use tracing::debug;
use walkdir::WalkDir;

use crate::strip_prefix::strip_prefix;

Expand Down Expand Up @@ -46,11 +45,16 @@ 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 ignore::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()
.ok_or_else(|| anyhow::anyhow!("unknown file type"))?;
if file_type.is_dir() {
if destination == to {
continue;
Expand Down Expand Up @@ -86,7 +90,7 @@ fn copy_directory(from: &Path, to: std::path::PathBuf) -> Result<(), anyhow::Err

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

0 comments on commit 5e80351

Please sign in to comment.