mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2025-01-04 07:25:44 +03:00
Check if a file is executable and use that mode
This commit is contained in:
parent
b810a73d2f
commit
62bc434869
@ -10,6 +10,8 @@ use std::{
|
|||||||
collections::{HashMap, HashSet},
|
collections::{HashMap, HashSet},
|
||||||
fmt, path, time, vec,
|
fmt, path, time, vec,
|
||||||
};
|
};
|
||||||
|
use std::os::unix::fs::PermissionsExt;
|
||||||
|
|
||||||
|
|
||||||
use anyhow::{bail, Context, Result};
|
use anyhow::{bail, Context, Result};
|
||||||
use diffy::{apply_bytes, Patch};
|
use diffy::{apply_bytes, Patch};
|
||||||
@ -1878,6 +1880,15 @@ fn write_tree(
|
|||||||
|
|
||||||
// if file exists
|
// if file exists
|
||||||
if full_path.exists() {
|
if full_path.exists() {
|
||||||
|
// if file is executable, use 755, otherwise 644
|
||||||
|
let mut filemode = git2::FileMode::Blob;
|
||||||
|
// check if full_path file is executable
|
||||||
|
if let Ok(metadata) = std::fs::metadata(&full_path) {
|
||||||
|
if metadata.permissions().mode() & 0o111 != 0 {
|
||||||
|
filemode = git2::FileMode::BlobExecutable;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// get the blob
|
// get the blob
|
||||||
if let Ok(tree_entry) = base_tree.get_path(rel_path) {
|
if let Ok(tree_entry) = base_tree.get_path(rel_path) {
|
||||||
// blob from tree_entry
|
// blob from tree_entry
|
||||||
@ -1906,11 +1917,11 @@ fn write_tree(
|
|||||||
// create a blob
|
// create a blob
|
||||||
let new_blob_oid = git_repository.blob(&new_content)?;
|
let new_blob_oid = git_repository.blob(&new_content)?;
|
||||||
// upsert into the builder
|
// upsert into the builder
|
||||||
builder.upsert(rel_path, new_blob_oid, git2::FileMode::Blob);
|
builder.upsert(rel_path, new_blob_oid, filemode);
|
||||||
} else {
|
} else {
|
||||||
// create a git blob from a file on disk
|
// create a git blob from a file on disk
|
||||||
let blob_oid = git_repository.blob_path(&full_path)?;
|
let blob_oid = git_repository.blob_path(&full_path)?;
|
||||||
builder.upsert(rel_path, blob_oid, git2::FileMode::Blob);
|
builder.upsert(rel_path, blob_oid, filemode);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// remove file from index
|
// remove file from index
|
||||||
|
Loading…
Reference in New Issue
Block a user