Skip to content
Merged
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
6 changes: 3 additions & 3 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion cpp-linter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ thiserror = { workspace = true }
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }

[dependencies.git-bot-feedback]
version = "0.12.3"
version = "0.12.4"
Comment thread
2bndy5 marked this conversation as resolved.
Resolved
features = ["file-changes"]
# path = "../../git-bot-feedback"
# git = "https://github.com/2bndy5/git-bot-feedback"
Expand Down
12 changes: 11 additions & 1 deletion cpp-linter/src/rest_client/feedback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,17 @@ impl RestClient {
for annotation in &mut annotations {
annotation.path = prefix_feedback_path(&annotation.path, &self.repo_root_prefix);
}
self.client.write_file_annotations(&annotations)?;
if self.client.client_kind() == "local" && feedback_inputs.report_to_stdout() {
// The local client prints annotations to stdout,
// which must hold only the report.
let mut err = stderr().lock();
for annotation in &annotations {
writeln!(err, "{}", annotation.fmt_local())
.map_err(ClientError::StdoutWriteFailed)?;
}
} else {
self.client.write_file_annotations(&annotations)?;
}
if self.client.client_kind() == "github"
&& let Some(msg) = annotation_cap_message(&annotations, &feedback_inputs)
{
Expand Down
12 changes: 9 additions & 3 deletions cpp-linter/src/rest_client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,15 @@ impl RestClient {
ignore_index: bool,
) -> Result<Vec<FileObj>, ClientError> {
let mut changed_files_filter = file_filter.clone();
changed_files_filter.ignored.clear();
changed_files_filter.not_ignored.clear();
changed_files_filter.not_ignored.insert(String::new());
if !self.repo_root_prefix.as_os_str().is_empty() {
// The patterns are relative to `--repo-root`, but the client lists files
// relative to the git root, so they are applied after the prefix is removed.
// Without a prefix, the client applies them itself and doesn't read
// ignored untracked files at all.
changed_files_filter.ignored.clear();
changed_files_filter.not_ignored.clear();
changed_files_filter.not_ignored.insert(String::new());
}
let files = self
.client
.get_list_of_changed_files(
Expand Down
67 changes: 67 additions & 0 deletions cpp-linter/src/rest_client/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -897,3 +897,70 @@ fn annotations_over_step_limit() {
"{msg}"
);
}

// ************************* tests for listing changed files

/// An ignored untracked file is not read, so one that can't be read doesn't stop the run.
#[cfg(unix)]
#[tokio::test]
async fn ignored_untracked_file_is_not_read() {
use std::{fs, os::unix::fs::PermissionsExt, process::Command};

let tmp = tempdir().unwrap();
let root = tmp.path().canonicalize().unwrap();
let git = |args: &[&str]| {
let status = Command::new("git")
.current_dir(&root)
.args(args)
.status()
.unwrap();
assert!(status.success(), "git {args:?}");
};
git(&["init", "-q"]);
git(&[
"-c",
"user.name=test",
"-c",
"user.email=test@example.com",
"commit",
"-q",
"--allow-empty",
"-m",
"init",
]);
fs::create_dir_all(root.join("src")).unwrap();
fs::write(root.join("src/ok.cpp"), "int main() {}\n").unwrap();
fs::create_dir_all(root.join("vendor")).unwrap();
let unreadable = root.join("vendor/broken.cpp");
fs::write(&unreadable, "int x;\n").unwrap();
fs::set_permissions(&unreadable, fs::Permissions::from_mode(0o000)).unwrap();

// a local run, not a CI run
unsafe {
for var in [
"GITHUB_ACTIONS",
"GITEA_ACTIONS",
"FORGEJO_ACTIONS",
"GITLAB_CI",
] {
env::remove_var(var);
}
}
let cur_dir = env::current_dir().unwrap();
env::set_current_dir(&root).unwrap();
let client = RestClient::new(&root).unwrap();
assert_eq!(client.client_kind(), "local");
let file_filter = FileFilter::new(&["vendor"], &["cpp"], None);
let files = client
.get_list_of_changed_files(
&file_filter,
&git_bot_feedback::LinesChangedOnly::Off,
&None,
false,
)
.await;
env::set_current_dir(cur_dir).unwrap();

let names: Vec<PathBuf> = files.unwrap().into_iter().map(|f| f.name).collect();
assert_eq!(names, vec![PathBuf::from("src/ok.cpp")]);
}
Loading