Nicer, somewhat more consistent messaging.
parent
a43561832f
commit
d1d0c8f172
|
@ -163,7 +163,7 @@ pub fn load(candidates: &Vec<ResPathBuf>) -> Result<PathConfig> {
|
|||
|
||||
pub fn reload(pc: &PathConfig) -> Result<PathConfig> {
|
||||
info!(
|
||||
"<green>{}</> configuration reloaded.",
|
||||
"<bold>Reloaded:</> Configuration <cyan>{}</>.",
|
||||
pc.config.repos.local.display()
|
||||
);
|
||||
load(&vec![pc.homesync_yml.clone()])
|
||||
|
@ -177,7 +177,7 @@ pub fn list_packages(pc: PathConfig) {
|
|||
println!(
|
||||
"Listing packages in {}...\n",
|
||||
colorize_string(format!(
|
||||
"<green>{}</>",
|
||||
"<cyan>{}</>",
|
||||
pc.homesync_yml.unresolved().display()
|
||||
)),
|
||||
);
|
||||
|
|
17
src/copy.rs
17
src/copy.rs
|
@ -8,6 +8,8 @@ use std::{
|
|||
result,
|
||||
};
|
||||
|
||||
// TODO(jrpotter): Validate local path is a git repository.
|
||||
|
||||
// ========================================
|
||||
// Error
|
||||
// ========================================
|
||||
|
@ -69,7 +71,7 @@ fn apply_all(pc: &PathConfig) -> Result<()> {
|
|||
if let Some(value) = path {
|
||||
fs::copy(repo_file.resolved(), value.resolved())?;
|
||||
info!(
|
||||
"Copied `{}` from local repository.",
|
||||
"<bold>Copied:</> <cyan>{}</> from local repository.",
|
||||
repo_file.unresolved().display(),
|
||||
);
|
||||
} else {
|
||||
|
@ -82,7 +84,7 @@ fn apply_all(pc: &PathConfig) -> Result<()> {
|
|||
}
|
||||
fs::copy(repo_file.resolved(), expanded)?;
|
||||
info!(
|
||||
"Copied `{}` from local repository.",
|
||||
"<bold>Copied:</> <cyan>{}</> from local repository.",
|
||||
repo_file.unresolved().display(),
|
||||
);
|
||||
}
|
||||
|
@ -109,10 +111,13 @@ fn apply_one(pc: &PathConfig, package: &str) -> Result<()> {
|
|||
fs::create_dir_all(p)?;
|
||||
}
|
||||
fs::copy(repo_file, expanded)?;
|
||||
info!("Copied `{}` from local repository.", path.display());
|
||||
info!(
|
||||
"<bold>Copied:</> <cyan>{}</> from local repository.",
|
||||
path.display()
|
||||
);
|
||||
}
|
||||
} else {
|
||||
warn!("Could not find package `{}` in config.", package);
|
||||
warn!("Could not find package <cyan>{}</> in config.", package);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -152,7 +157,7 @@ pub fn stage(pc: &PathConfig) -> Result<()> {
|
|||
// repository.
|
||||
for (key, value) in &package_lookup {
|
||||
if let Some(value) = value {
|
||||
let mut copy = value.resolved().to_path_buf();
|
||||
let mut copy = workdir.resolved().to_path_buf();
|
||||
copy.push(key);
|
||||
if let Some(p) = copy.parent() {
|
||||
fs::create_dir_all(p)?;
|
||||
|
@ -162,7 +167,7 @@ pub fn stage(pc: &PathConfig) -> Result<()> {
|
|||
}
|
||||
|
||||
info!(
|
||||
"Staged files. Run <italic>git -C <green>{}</> <italic>status</> to see what changed.",
|
||||
"<bold>Staged:</> View using `<italic>git -C <cyan>{}</> <italic>status</>`.",
|
||||
&pc.config.repos.local.display()
|
||||
);
|
||||
|
||||
|
|
|
@ -160,20 +160,20 @@ pub fn launch(mut pc: PathConfig, freq_secs: u64) -> Result<(), Box<dyn Error>>
|
|||
// Received paths should always be fully resolved.
|
||||
match watch_rx.recv() {
|
||||
Ok(DebouncedEvent::NoticeWrite(p)) => {
|
||||
trace!("NoticeWrite '{}'", p.display());
|
||||
trace!("<bold>Noticed:</> Write at <cyan>{}</>", p.display());
|
||||
}
|
||||
Ok(DebouncedEvent::NoticeRemove(p)) => {
|
||||
trace!("NoticeRemove '{}'", p.display());
|
||||
trace!("<bold>Noticed:</> Removal of <cyan>{}</>", p.display());
|
||||
}
|
||||
Ok(DebouncedEvent::Create(p)) => {
|
||||
trace!("Create '{}'", p.display());
|
||||
trace!("<bold>Created:</> <cyan>{}</>", p.display());
|
||||
if pc.homesync_yml == p {
|
||||
pc = config::reload(&pc)?;
|
||||
state.update(&pc);
|
||||
}
|
||||
}
|
||||
Ok(DebouncedEvent::Write(p)) => {
|
||||
trace!("Write '{}'", p.display());
|
||||
trace!("<bold>Wrote:</> <cyan>{}</>", p.display());
|
||||
if pc.homesync_yml == p {
|
||||
pc = config::reload(&pc)?;
|
||||
state.update(&pc);
|
||||
|
@ -184,26 +184,32 @@ pub fn launch(mut pc: PathConfig, freq_secs: u64) -> Result<(), Box<dyn Error>>
|
|||
// e.g. been removed, let's just keep using what we have in memory
|
||||
// in the chance it may be added back.
|
||||
Ok(DebouncedEvent::Chmod(p)) => {
|
||||
trace!("Chmod '{}'", p.display());
|
||||
trace!("<bold>Chmod:</> <cyan>{}</>", p.display());
|
||||
}
|
||||
Ok(DebouncedEvent::Remove(p)) => {
|
||||
if pc.homesync_yml == p {
|
||||
warn!(
|
||||
"Removed primary config '{}'. Continuing to use last loaded state",
|
||||
"<bold>Removed:</> Primary config <cyan>{}</>. Continuing to use last \
|
||||
loaded state",
|
||||
p.display()
|
||||
);
|
||||
} else {
|
||||
trace!("Remove '{}'", p.display());
|
||||
trace!("<bold>Removed:</> <cyan>{}</>", p.display());
|
||||
}
|
||||
}
|
||||
Ok(DebouncedEvent::Rename(src, dst)) => {
|
||||
if pc.homesync_yml == src && pc.homesync_yml != dst {
|
||||
warn!(
|
||||
"Renamed primary config '{}'. Continuing to use last loaded state",
|
||||
"<bold>Renamed:</> Primary config <cyan>{}</>. Continuing from last \
|
||||
loaded state",
|
||||
src.display()
|
||||
);
|
||||
} else {
|
||||
trace!("Renamed '{}' to '{}'", src.display(), dst.display())
|
||||
trace!(
|
||||
"<bold>Renamed:</> <cyan>{}</> to <cyan>{}</>.",
|
||||
src.display(),
|
||||
dst.display()
|
||||
)
|
||||
}
|
||||
}
|
||||
Ok(DebouncedEvent::Rescan) => {
|
||||
|
@ -211,7 +217,7 @@ pub fn launch(mut pc: PathConfig, freq_secs: u64) -> Result<(), Box<dyn Error>>
|
|||
}
|
||||
Ok(DebouncedEvent::Error(e, path)) => {
|
||||
warn!(
|
||||
"Error {} at '{}'",
|
||||
"<bold>Unexpected:</> Error {} at <cyan>{}</>",
|
||||
e,
|
||||
path.unwrap_or_else(|| PathBuf::from("N/A")).display()
|
||||
);
|
||||
|
|
42
src/git.rs
42
src/git.rs
|
@ -106,7 +106,7 @@ pub fn init(pc: &PathConfig) -> Result<Repository> {
|
|||
match Repository::open(&expanded) {
|
||||
Ok(repo) => {
|
||||
info!(
|
||||
"Opened local repository <green>{}</>.",
|
||||
"<bold>Opened:</> Local repository <cyan>{}</>.",
|
||||
&pc.config.repos.local.display()
|
||||
);
|
||||
Ok(repo)
|
||||
|
@ -114,7 +114,7 @@ pub fn init(pc: &PathConfig) -> Result<Repository> {
|
|||
Err(e) if e.code() == git2::ErrorCode::NotFound => match clone(pc, &expanded) {
|
||||
Ok(repo) => {
|
||||
info!(
|
||||
"Cloned remote repository <green>{}</>.",
|
||||
"<bold>Cloned:</> Remote repository <cyan>{}</>.",
|
||||
&pc.config.repos.remote.url
|
||||
);
|
||||
Ok(repo)
|
||||
|
@ -122,11 +122,12 @@ pub fn init(pc: &PathConfig) -> Result<Repository> {
|
|||
Err(Error::GitError(e))
|
||||
if e.class() == git2::ErrorClass::Ssh && e.code() == git2::ErrorCode::Eof =>
|
||||
{
|
||||
let repo = Repository::init(&expanded)?;
|
||||
info!(
|
||||
"Creating local repository at <green>{}</>.",
|
||||
"<bold>Created:</> Local repository <cyan>{}</>.",
|
||||
pc.config.repos.local.display()
|
||||
);
|
||||
Ok(Repository::init(&expanded)?)
|
||||
Ok(repo)
|
||||
}
|
||||
Err(e) => Err(e)?,
|
||||
},
|
||||
|
@ -161,7 +162,7 @@ pub fn push(pc: &PathConfig, repo: &mut Repository) -> Result<()> {
|
|||
// Want to also reflect this change on the working directory.
|
||||
index.write()?;
|
||||
let index_tree = repo.find_tree(index_oid)?;
|
||||
info!("Writing index to tree `{}`.", index_oid);
|
||||
info!("<bold>Wrote:</> Index to tree <cyan>{}</>.", index_oid);
|
||||
|
||||
// Commit our changes and push them to our remote.
|
||||
// TODO(jrpotter): Come up with a more useful message.
|
||||
|
@ -186,7 +187,7 @@ pub fn push(pc: &PathConfig, repo: &mut Repository) -> Result<()> {
|
|||
&[],
|
||||
)?
|
||||
};
|
||||
info!("Commited `{}` with message \"{}\".", commit_oid, message);
|
||||
info!("<bold>Commited:</> <cyan>{}</>.", commit_oid);
|
||||
|
||||
let mut remote = find_remote(pc, repo)?;
|
||||
let call_options = get_remote_callbacks(pc)?;
|
||||
|
@ -195,7 +196,7 @@ pub fn push(pc: &PathConfig, repo: &mut Repository) -> Result<()> {
|
|||
let mut push_options = get_push_options(pc)?;
|
||||
remote.push(&[&format!("{r}:{r}", r = refspec)], Some(&mut push_options))?;
|
||||
info!(
|
||||
"Pushed changes to remote `{}`.",
|
||||
"<bold>Pushed:</> Changes to remote <cyan>{}</>.",
|
||||
pc.config.repos.remote.tracking_branch(),
|
||||
);
|
||||
|
||||
|
@ -212,7 +213,10 @@ fn local_from_remote(pc: &PathConfig, repo: &Repository) -> Result<()> {
|
|||
// It should never be the case this function is called when the local branch
|
||||
// exists. Keep `force` to `false` to catch any misuse here.
|
||||
repo.branch_from_annotated_commit(&pc.config.repos.remote.branch, &remote_ref, false)?;
|
||||
info!("Created new local branch from `{}`.", &tracking_branch);
|
||||
info!(
|
||||
"<bold>Created</>: Local branch <cyan>{}</>.",
|
||||
&pc.config.repos.remote.branch
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -233,7 +237,10 @@ fn local_rebase_remote(pc: &PathConfig, repo: &Repository) -> Result<()> {
|
|||
let signature = now_signature(pc)?;
|
||||
repo.rebase(Some(&local_ref), Some(&remote_ref), None, None)?
|
||||
.finish(Some(&signature))?;
|
||||
info!("Rebased local branch onto `{}`.", &tracking_branch);
|
||||
info!(
|
||||
"<bold>Rebased:</> Local branch onto <cyan>{}<cyan>.",
|
||||
&tracking_branch
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -267,7 +274,7 @@ pub fn pull(pc: &PathConfig, repo: &mut Repository) -> Result<()> {
|
|||
if let Some(mut index) = index_with_all(repo)? {
|
||||
let index_oid = index.write_tree()?;
|
||||
let index_tree = repo.find_tree(index_oid)?;
|
||||
info!("Writing tree `{}`.", index_oid);
|
||||
info!("<bold>Wrote:</> Index to tree <cyan>{}</>.", index_oid);
|
||||
|
||||
let signature = now_signature(pc)?;
|
||||
let message = "Save potentially conflicting files here.";
|
||||
|
@ -283,7 +290,7 @@ pub fn pull(pc: &PathConfig, repo: &mut Repository) -> Result<()> {
|
|||
&index_tree,
|
||||
&[&parent_commit],
|
||||
)?;
|
||||
info!("Saved potentially conflicting files in new commit of HEAD.");
|
||||
info!("<bold>Saved:</> Potentially conflicting files in new commit of <cyan>HEAD</>.");
|
||||
} else {
|
||||
let temp_branch = temporary_branch_name(pc, repo)?;
|
||||
let refspec = format!("refs/heads/{}", &temp_branch);
|
||||
|
@ -296,7 +303,7 @@ pub fn pull(pc: &PathConfig, repo: &mut Repository) -> Result<()> {
|
|||
&[],
|
||||
)?;
|
||||
info!(
|
||||
"Saved potentially conflicting files on branch <yellow>{}</>",
|
||||
"<bold>Saved:</> Potentially conflicting files on branch <cyan>{}</>.",
|
||||
temp_branch
|
||||
);
|
||||
}
|
||||
|
@ -347,7 +354,7 @@ where
|
|||
Some(StashFlags::INCLUDE_UNTRACKED),
|
||||
) {
|
||||
Ok(oid) => {
|
||||
info!("Stashing changes in `{}`.", oid);
|
||||
info!("<bold>Stashed:</> Changes in <cyan>{}</>.", oid);
|
||||
Some(oid)
|
||||
}
|
||||
Err(e) if e.class() == git2::ErrorClass::Stash && e.code() == git2::ErrorCode::NotFound => {
|
||||
|
@ -379,9 +386,9 @@ where
|
|||
apply_options.checkout_options(checkout);
|
||||
|
||||
repo.stash_apply(index, Some(&mut apply_options))?;
|
||||
info!("Reapplied stash `{}`.", oid);
|
||||
info!("<bold>Applied</> Stash <cyan>{}</>.", oid);
|
||||
} else {
|
||||
warn!("Could not find stash `{}`. Ignoring.", oid);
|
||||
warn!("Could not find stash <cyan>{}<cyan>. Ignoring.", oid);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -418,7 +425,10 @@ fn fetch_remote<'repo>(pc: &PathConfig, repo: &'repo Repository) -> Result<Remot
|
|||
None,
|
||||
)?;
|
||||
let tracking_branch = pc.config.repos.remote.tracking_branch();
|
||||
info!("Fetched remote branch `{}`.", &tracking_branch);
|
||||
info!(
|
||||
"<bold>Fetched:</> Remote branch <cyan>{}<cyan>.",
|
||||
&tracking_branch
|
||||
);
|
||||
|
||||
Ok(remote)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue