Skip to content

Commit

Permalink
git rs warning
Browse files Browse the repository at this point in the history
  • Loading branch information
olegklimov committed Dec 27, 2024
1 parent 2b69add commit 12192bf
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl FileChangeStatus {
pub fn git_ls_files(repository_path: &PathBuf) -> Option<Vec<PathBuf>> {
let repository = Repository::open(repository_path)
.map_err(|e| error!("Failed to open repository: {}", e)).ok()?;

let mut status_options = StatusOptions::new();
status_options
.include_untracked(true)
Expand Down Expand Up @@ -97,7 +97,7 @@ pub fn git_ls_files(repository_path: &PathBuf) -> Option<Vec<PathBuf>> {
pub fn stage_changes(repository: &Repository, file_changes: &Vec<FileChange>) -> Result<(), String> {
let mut index = repository.index()
.map_err(|e| format!("Failed to get index: {}", e))?;

for file_change in file_changes {
match file_change.status {
FileChangeStatus::ADDED | FileChangeStatus::MODIFIED => {
Expand All @@ -110,10 +110,10 @@ pub fn stage_changes(repository: &Repository, file_changes: &Vec<FileChange>) ->
},
}
}

index.write()
.map_err(|e| format!("Failed to write index: {}", e))?;

Ok(())
}

Expand All @@ -124,24 +124,24 @@ pub fn get_file_changes(repository: &Repository, include_unstaged: bool) -> Resu
.map_err(|e| format!("Failed to get statuses: {}", e))?;
for entry in statuses.iter() {
let status = entry.status();
if status.contains(Status::INDEX_NEW) {
result.push(FileChange {status: FileChangeStatus::ADDED, path: entry.path().unwrap().to_string()})
if status.contains(Status::INDEX_NEW) {
result.push(FileChange {status: FileChangeStatus::ADDED, path: entry.path().unwrap().to_string()})
}
if status.contains(Status::INDEX_MODIFIED) {
result.push(FileChange {status: FileChangeStatus::MODIFIED, path: entry.path().unwrap().to_string()})
if status.contains(Status::INDEX_MODIFIED) {
result.push(FileChange {status: FileChangeStatus::MODIFIED, path: entry.path().unwrap().to_string()})
}
if status.contains(Status::INDEX_DELETED) {
result.push(FileChange {status: FileChangeStatus::DELETED, path: entry.path().unwrap().to_string()})
if status.contains(Status::INDEX_DELETED) {
result.push(FileChange {status: FileChangeStatus::DELETED, path: entry.path().unwrap().to_string()})
}
if include_unstaged {
if status.contains(Status::WT_NEW) {
result.push(FileChange {status: FileChangeStatus::ADDED, path: entry.path().unwrap().to_string()})
if status.contains(Status::WT_NEW) {
result.push(FileChange {status: FileChangeStatus::ADDED, path: entry.path().unwrap().to_string()})
}
if status.contains(Status::WT_MODIFIED) {
result.push(FileChange {status: FileChangeStatus::MODIFIED, path: entry.path().unwrap().to_string()})
if status.contains(Status::WT_MODIFIED) {
result.push(FileChange {status: FileChangeStatus::MODIFIED, path: entry.path().unwrap().to_string()})
}
if status.contains(Status::WT_DELETED) {
result.push(FileChange {status: FileChangeStatus::DELETED, path: entry.path().unwrap().to_string()})
if status.contains(Status::WT_DELETED) {
result.push(FileChange {status: FileChangeStatus::DELETED, path: entry.path().unwrap().to_string()})
}
}
}
Expand All @@ -159,7 +159,7 @@ pub fn get_configured_author_email_and_name(repository: &Repository) -> Result<(
}

pub fn commit(repository: &Repository, branch: &Branch, message: &str, author_name: &str, author_email: &str) -> Result<Oid, String> {

let mut index = repository.index()
.map_err(|e| format!("Failed to get index: {}", e))?;
let tree_id = index.write_tree()
Expand Down Expand Up @@ -237,13 +237,13 @@ pub async fn get_commit_information_from_current_changes(gcx: Arc<ARwLock<Global
for project_path in crate::files_correction::get_project_dirs(gcx.clone()).await {
let repository = match git2::Repository::open(&project_path) {
Ok(repo) => repo,
Err(e) => { error!("{}", e); continue; }
Err(e) => { tracing::warn!("{}", e); continue; }
};

let file_changes = match crate::git::get_file_changes(&repository, true) {
Ok(changes) if changes.is_empty() => { continue; }
Ok(changes) => changes,
Err(e) => { error!("{}", e); continue; }
Err(e) => { tracing::warn!("{}", e); continue; }
};

commits.push(CommitInfo {
Expand Down

0 comments on commit 12192bf

Please sign in to comment.