summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMica White <botahamec@outlook.com>2026-03-30 20:42:35 -0400
committerMica White <botahamec@outlook.com>2026-03-30 20:42:35 -0400
commitda6cb19c293c4998a5d8152b3660dc5e8d3b26e0 (patch)
tree8b7c1c421d47337016812cbd744ff026b15e492f /src
parent35d9842bded06b4d048b9722dfbdffad748f14c5 (diff)
Add check for executability
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 5a6b7df..0eeee6d 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -36,6 +36,7 @@ use git2::{
Commit, FetchOptions, MergeOptions, Oid, PushOptions, Reference, RemoteCallbacks, Repository,
Signature, Time, Tree,
};
+use is_executable::is_executable;
use serde::{Deserialize, Serialize};
use thiserror::Error;
use uuid::Uuid;
@@ -136,16 +137,17 @@ pub fn current_branch(repository: &Repository) -> Result<String, git2::Error> {
Ok(branch_name)
}
-pub fn filemode_for_dir_entry(metadata: &Metadata) -> i32 {
- if metadata.is_dir() {
+pub fn filemode_for_dir_entry(path: &Path) -> std::io::Result<i32> {
+ let metadata = path.metadata()?;
+ Ok(if metadata.is_dir() {
0o040000
} else if metadata.is_symlink() {
0o120000
- } else if metadata.permissions().readonly() {
- 0o100644
- } else {
+ } else if is_executable(path) {
0o100755
- }
+ } else {
+ 0o100644
+ })
}
pub fn path_to_tree(repository: &Repository, path: &Path) -> Result<Oid, TreeError> {
@@ -160,7 +162,7 @@ pub fn path_to_tree(repository: &Repository, path: &Path) -> Result<Oid, TreeErr
continue;
}
- let filemode = filemode_for_dir_entry(&entry.metadata()?);
+ let filemode = filemode_for_dir_entry(&entry.path())?;
let oid = path_to_tree(repository, &entry.path())?;
let filename = entry.file_name();
tree.insert(filename, oid, filemode)?;