mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-12-19 15:41:31 +03:00
make the alternates path writing more robust
This commit is contained in:
parent
c2b4087e93
commit
3d475b7a3c
@ -1,9 +1,13 @@
|
|||||||
use std::{path, str};
|
use std::{
|
||||||
|
io::Write,
|
||||||
|
path::{self, Path},
|
||||||
|
str,
|
||||||
|
};
|
||||||
|
|
||||||
use git2::Submodule;
|
use git2::Submodule;
|
||||||
use git2_hooks::HookResult;
|
use git2_hooks::HookResult;
|
||||||
|
|
||||||
use crate::keys;
|
use crate::{keys, path::Normalize};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
Blob, Branch, Commit, Config, Index, Oid, Reference, Refname, Remote, Result, Signature, Tree,
|
Blob, Branch, Commit, Config, Index, Oid, Reference, Refname, Remote, Result, Signature, Tree,
|
||||||
@ -50,10 +54,13 @@ impl Repository {
|
|||||||
Ok(Repository(inner))
|
Ok(Repository(inner))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_disk_alternate(&self, path: &str) -> Result<()> {
|
pub fn add_disk_alternate<P: AsRef<Path>>(&self, path: P) -> Result<()> {
|
||||||
let alternates_path = self.0.path().join("objects/info/alternates");
|
let alternates_path = self.0.path().join("objects/info/alternates");
|
||||||
if !alternates_path.exists() {
|
if !alternates_path.exists() {
|
||||||
std::fs::write(alternates_path, format!("{path}\n"))?;
|
let path = path.as_ref().normalize();
|
||||||
|
let mut alternates_file = std::fs::File::create(&alternates_path)?;
|
||||||
|
alternates_file.write_all(path.as_path().as_os_str().as_encoded_bytes())?;
|
||||||
|
alternates_file.write_all(b"\n")?;
|
||||||
self.0.odb().and_then(|odb| odb.refresh())?;
|
self.0.odb().and_then(|odb| odb.refresh())?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user