Compare commits
No commits in common. "9c54a92152f58d7868023eb2ffcadf9b9e0f4dcb" and "4d6e18a9f425d90f89b069c90d11fa89c3afd2d6" have entirely different histories.
9c54a92152
...
4d6e18a9f4
3 changed files with 2 additions and 83 deletions
|
|
@ -45,15 +45,6 @@ enum Commands {
|
||||||
issue_id: String,
|
issue_id: String,
|
||||||
description: Option<String>,
|
description: Option<String>,
|
||||||
},
|
},
|
||||||
|
|
||||||
/// Sync entomologist data with remote. This fetches from the remote,
|
|
||||||
/// merges the remote entomologist data branch with the local one,
|
|
||||||
/// and pushes the result back to the remote.
|
|
||||||
Sync {
|
|
||||||
/// Name of the git remote to sync with.
|
|
||||||
#[arg(default_value_t = String::from("origin"))]
|
|
||||||
remote: String,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_command(args: &Args, issues_dir: &std::path::Path) -> anyhow::Result<()> {
|
fn handle_command(args: &Args, issues_dir: &std::path::Path) -> anyhow::Result<()> {
|
||||||
|
|
@ -163,24 +154,6 @@ fn handle_command(args: &Args, issues_dir: &std::path::Path) -> anyhow::Result<(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Commands::Sync { remote } => {
|
|
||||||
if args.issues_dir.is_some() {
|
|
||||||
return Err(anyhow::anyhow!(
|
|
||||||
"`sync` operates on a branch, don't specify `issues_dir`"
|
|
||||||
));
|
|
||||||
}
|
|
||||||
// FIXME: Kinda bogus to re-do this thing we just did in
|
|
||||||
// `main()`. Maybe `main()` shouldn't create the worktree,
|
|
||||||
// maybe we should do it here in `handle_command()`?
|
|
||||||
// That way also each command could decide if it wants a
|
|
||||||
// read-only worktree or a read/write one.
|
|
||||||
let branch = match &args.issues_branch {
|
|
||||||
Some(branch) => branch,
|
|
||||||
None => "entomologist-data",
|
|
||||||
};
|
|
||||||
entomologist::git::sync(issues_dir, remote, branch)?;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
||||||
56
src/git.rs
56
src/git.rs
|
|
@ -124,62 +124,6 @@ pub fn git_commit_file(file: &std::path::Path) -> Result<(), GitError> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn git_fetch(dir: &std::path::Path, remote: &str) -> Result<(), GitError> {
|
|
||||||
let result = std::process::Command::new("git")
|
|
||||||
.args(["fetch", remote])
|
|
||||||
.current_dir(dir)
|
|
||||||
.output()?;
|
|
||||||
if !result.status.success() {
|
|
||||||
println!("stdout: {}", std::str::from_utf8(&result.stdout).unwrap());
|
|
||||||
println!("stderr: {}", std::str::from_utf8(&result.stderr).unwrap());
|
|
||||||
return Err(GitError::Oops);
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn sync(dir: &std::path::Path, remote: &str, branch: &str) -> Result<(), GitError> {
|
|
||||||
// We do all the work in a directory that's (FIXME) hopefully a
|
|
||||||
// worktree. If anything goes wrong we just fail out and ask the
|
|
||||||
// human to fix it by hand :-/
|
|
||||||
// 1. `git fetch`
|
|
||||||
// 2. `git merge REMOTE/BRANCH`
|
|
||||||
// 3. `git push REMOTE BRANCH`
|
|
||||||
|
|
||||||
git_fetch(dir, remote)?;
|
|
||||||
|
|
||||||
// Merge remote branch into local.
|
|
||||||
let result = std::process::Command::new("git")
|
|
||||||
.args(["merge", &format!("{}/{}", remote, branch)])
|
|
||||||
.current_dir(dir)
|
|
||||||
.output()?;
|
|
||||||
if !result.status.success() {
|
|
||||||
println!(
|
|
||||||
"Sync failed! Merge error! Help, a human needs to fix the mess in {:?}",
|
|
||||||
dir
|
|
||||||
);
|
|
||||||
println!("stdout: {}", std::str::from_utf8(&result.stdout).unwrap());
|
|
||||||
println!("stderr: {}", std::str::from_utf8(&result.stderr).unwrap());
|
|
||||||
return Err(GitError::Oops);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Push merged branch to remote.
|
|
||||||
let result = std::process::Command::new("git")
|
|
||||||
.args(["push", remote, branch])
|
|
||||||
.current_dir(dir)
|
|
||||||
.output()?;
|
|
||||||
if !result.status.success() {
|
|
||||||
println!(
|
|
||||||
"Sync failed! Push error! Help, a human needs to fix the mess in {:?}",
|
|
||||||
dir
|
|
||||||
);
|
|
||||||
println!("stdout: {}", std::str::from_utf8(&result.stdout).unwrap());
|
|
||||||
println!("stderr: {}", std::str::from_utf8(&result.stderr).unwrap());
|
|
||||||
return Err(GitError::Oops);
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn create_orphan_branch(branch: &str) -> Result<(), GitError> {
|
pub fn create_orphan_branch(branch: &str) -> Result<(), GitError> {
|
||||||
{
|
{
|
||||||
let tmp_worktree = tempfile::tempdir().unwrap();
|
let tmp_worktree = tempfile::tempdir().unwrap();
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,7 @@ impl fmt::Display for State {
|
||||||
State::InProgress => "inprogress",
|
State::InProgress => "inprogress",
|
||||||
State::Done => "done",
|
State::Done => "done",
|
||||||
State::WontDo => "wontdo",
|
State::WontDo => "wontdo",
|
||||||
|
|
||||||
};
|
};
|
||||||
write!(f, "{fmt_str}")
|
write!(f, "{fmt_str}")
|
||||||
}
|
}
|
||||||
|
|
@ -144,6 +145,7 @@ impl Issue {
|
||||||
let mut dir = std::path::PathBuf::from(&self.dir);
|
let mut dir = std::path::PathBuf::from(&self.dir);
|
||||||
dir.push("comments");
|
dir.push("comments");
|
||||||
if !dir.exists() {
|
if !dir.exists() {
|
||||||
|
println!("creating {}", dir.to_string_lossy());
|
||||||
std::fs::create_dir(&dir)?;
|
std::fs::create_dir(&dir)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue