Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/commands/sourcemaps/inject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub fn make_command(command: Command) -> Command {
.short('i')
.value_name("IGNORE")
.action(ArgAction::Append)
.help("Ignores all files and folders matching the given glob"),
.help("Ignores all files and folders matching the given glob. Patterns are relative to the current directory, or absolute if starting with `/`."),
)
.arg(
Arg::new("ignore_file")
Expand Down
2 changes: 1 addition & 1 deletion src/commands/sourcemaps/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ pub fn make_command(command: Command) -> Command {
.short('i')
.value_name("IGNORE")
.action(ArgAction::Append)
.help("Ignores all files and folders matching the given glob"),
.help("Ignores all files and folders matching the given glob. Patterns are relative to the current directory, or absolute if starting with `/`."),
)
.arg(
Arg::new("ignore_file")
Expand Down
46 changes: 39 additions & 7 deletions src/utils/file_search.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use std::collections::BTreeSet;
use std::env;
use std::fs;
use std::io::Read as _;
use std::path::PathBuf;

use anyhow::Result;
use console::style;
use ignore::overrides::OverrideBuilder;
use glob::Pattern;
use ignore::types::TypesBuilder;
use ignore::WalkBuilder;
use log::{info, warn};
Expand Down Expand Up @@ -126,12 +127,43 @@ impl ReleaseFileSearch {
builder.add_ignore(ignore_file);
}

if !&self.ignores.is_empty() {
let mut override_builder = OverrideBuilder::new(&self.path);
for ignore in &self.ignores {
override_builder.add(ignore)?;
}
builder.overrides(override_builder.build()?);
// Compile ignore patterns relative to CWD (not relative to search path)
let cwd = env::current_dir()?;
let ignore_patterns: Vec<Pattern> = self
.ignores
.iter()
.filter_map(|pattern| {
// Patterns starting with ! are negations (handled in upload.rs/inject.rs)
// Remove the ! prefix for glob pattern compilation
let pattern_str = pattern.strip_prefix('!').unwrap_or(pattern);
match Pattern::new(pattern_str) {
Ok(p) => Some(p),
Err(e) => {
warn!("Invalid ignore pattern '{}': {}", pattern_str, e);
None
}
}
})
.collect();

// Use filter_entry to match patterns relative to CWD
if !ignore_patterns.is_empty() {
builder.filter_entry(move |entry| {
let entry_path = entry.path();

// Try to make the path relative to CWD, or use absolute path if that fails
let check_path = entry_path.strip_prefix(&cwd).unwrap_or(entry_path);

// Check if any pattern matches - if so, ignore (return false)
for pattern in &ignore_patterns {
if pattern.matches_path(check_path) {
return false;
}
}

// No patterns matched, keep this entry
true
});
}

for result in builder.build() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ Arguments:

Options:
-i, --ignore <IGNORE>
Ignores all files and folders matching the given glob
Ignores all files and folders matching the given glob. Patterns are relative to the
current directory, or absolute if starting with `/`.

-o, --org <ORG>
The organization ID or slug.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
```
$ sentry-cli sourcemaps inject path_a path_b --ignore "**/path_a/test/**" --dry-run
? success
> Searching path_a
> Found 2 files
> Searching path_b
> Found 4 files
> Analyzing 6 sources
> Analyzing completed in [..]
> Injecting debug ids

Source Map Debug ID Injection Report
Modified: The following source files have been modified to have debug ids
[..]-[..]-[..]-[..]-[..] - path_a/keep/file3.js
[..]-[..]-[..]-[..]-[..] - path_b/keep/file4.js
[..]-[..]-[..]-[..]-[..] - path_b/test/file2.js
Modified: The following sourcemap files have been modified to have debug ids
[..]-[..]-[..]-[..]-[..] - path_a/keep/file3.js.map
[..]-[..]-[..]-[..]-[..] - path_b/keep/file4.js.map
[..]-[..]-[..]-[..]-[..] - path_b/test/file2.js.map


```
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ Options:
--strip-common-prefix
Similar to --strip-prefix but strips the most common prefix on all sources references.
-i, --ignore <IGNORE>
Ignores all files and folders matching the given glob
Ignores all files and folders matching the given glob. Patterns are relative to the
current directory, or absolute if starting with `/`.
-I, --ignore-file <IGNORE_FILE>
Ignore all files and folders specified in the given ignore file, e.g. .gitignore.
--bundle <BUNDLE>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
```
$ sentry-cli sourcemaps upload path_a path_b --ignore "**/path_a/test/**" --url-prefix "~/" --validate
? failed
> Found 2 files
> Found 4 files
> Analyzing 6 sources
> Analyzing completed in [..]
> Rewriting sources
> Rewriting completed in [..]
> Adding source map references
> Validating sources
error: Cannot upload: You must either specify a release or have debug ids injected into your sources

Add --log-level=[info|debug] or export SENTRY_LOG_LEVEL=[info|debug] to see more output.
Please attach the full debug log to all bug reports.

```
2 changes: 2 additions & 0 deletions tests/integration/_fixtures/ignore_test/path_a/keep/file3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// This file should be kept
console.log("path_a/keep/file3.js");

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions tests/integration/_fixtures/ignore_test/path_a/test/file1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// This file should be ignored
console.log("path_a/test/file1.js");

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions tests/integration/_fixtures/ignore_test/path_b/keep/file4.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// This file should be kept
console.log("path_b/keep/file4.js");

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions tests/integration/_fixtures/ignore_test/path_b/test/file2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// This file should NOT be ignored (path_b/test is different from path_a/test)
console.log("path_b/test/file2.js");

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions tests/integration/sourcemaps/inject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,22 @@ fn command_sourcemaps_inject_double_association() {
);
}

#[test]
fn command_sourcemaps_inject_ignore_relative() {
let testcase_cwd_path =
"tests/integration/_cases/sourcemaps/sourcemaps-inject-ignore-relative.in/";
if std::path::Path::new(testcase_cwd_path).exists() {
remove_dir_all(testcase_cwd_path).unwrap();
}
copy_recursively(
"tests/integration/_fixtures/ignore_test/",
testcase_cwd_path,
)
.unwrap();

TestManager::new().register_trycmd_test("sourcemaps/sourcemaps-inject-ignore-relative.trycmd");
}

/// Recursively assert that the contents of two directories are equal.
///
/// We only support directories that contain exclusively text files.
Expand Down
22 changes: 22 additions & 0 deletions tests/integration/sourcemaps/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,25 @@ fn command_sourcemaps_upload_skip_invalid_utf8() {
.register_trycmd_test("sourcemaps/sourcemaps-with-invalid-utf8.trycmd")
.with_default_token();
}

#[test]
fn command_sourcemaps_upload_ignore_relative() {
use crate::integration::copy_recursively;
use std::fs::remove_dir_all;

let testcase_cwd_path =
"tests/integration/_cases/sourcemaps/sourcemaps-upload-ignore-relative.in/";
if std::path::Path::new(testcase_cwd_path).exists() {
remove_dir_all(testcase_cwd_path).unwrap();
}
copy_recursively(
"tests/integration/_fixtures/ignore_test/",
testcase_cwd_path,
)
.unwrap();

TestManager::new()
.mock_common_upload_endpoints(None, None)
.register_trycmd_test("sourcemaps/sourcemaps-upload-ignore-relative.trycmd")
.with_default_token();
}
Loading