mirror of
https://github.com/qwjyh/xdbm
synced 2025-04-21 04:05:49 +09:00
Compare commits
1 commit
dfb6694248
...
ed781612ec
Author | SHA1 | Date | |
---|---|---|---|
|
ed781612ec |
2 changed files with 52 additions and 3 deletions
18
src/main.rs
18
src/main.rs
|
@ -156,7 +156,23 @@ fn add_and_commit(repo: &Repository, path: &Path, message: &str) -> Result<Oid,
|
||||||
index.write()?;
|
index.write()?;
|
||||||
let oid = index.write_tree()?;
|
let oid = index.write_tree()?;
|
||||||
let tree = repo.find_tree(oid)?;
|
let tree = repo.find_tree(oid)?;
|
||||||
let config = repo.config()?;
|
let config = {
|
||||||
|
let mut config = git2::Config::open_default()?;
|
||||||
|
if log::log_enabled!(log::Level::Trace) {
|
||||||
|
trace!("before reading local config");
|
||||||
|
config
|
||||||
|
.entries(None)?
|
||||||
|
.for_each(|entry| trace!("{:?} = {:?}", entry.name(), entry.value()))?;
|
||||||
|
}
|
||||||
|
config.add_file(&path.join(".git/config"), git2::ConfigLevel::Local, false)?;
|
||||||
|
if log::log_enabled!(log::Level::Trace) {
|
||||||
|
trace!("after reading local config");
|
||||||
|
config
|
||||||
|
.entries(None)?
|
||||||
|
.for_each(|entry| trace!("{:?} = {:?}", entry.name(), entry.value()))?;
|
||||||
|
}
|
||||||
|
config
|
||||||
|
};
|
||||||
let signature = git2::Signature::now(
|
let signature = git2::Signature::now(
|
||||||
config.get_entry("user.name")?.value().unwrap(),
|
config.get_entry("user.name")?.value().unwrap(),
|
||||||
config.get_entry("user.email")?.value().unwrap(),
|
config.get_entry("user.email")?.value().unwrap(),
|
||||||
|
|
37
tests/cli.rs
37
tests/cli.rs
|
@ -2,9 +2,10 @@ mod integrated_test {
|
||||||
use std::{
|
use std::{
|
||||||
fs::{self, DirBuilder, File},
|
fs::{self, DirBuilder, File},
|
||||||
io::{self, BufWriter, Write},
|
io::{self, BufWriter, Write},
|
||||||
|
ops::Not,
|
||||||
};
|
};
|
||||||
|
|
||||||
use anyhow::{Ok, Result};
|
use anyhow::{Context, Ok, Result};
|
||||||
use assert_cmd::{assert::OutputAssertExt, Command};
|
use assert_cmd::{assert::OutputAssertExt, Command};
|
||||||
use git2::Repository;
|
use git2::Repository;
|
||||||
use log::trace;
|
use log::trace;
|
||||||
|
@ -40,6 +41,39 @@ mod integrated_test {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn git_init() -> Result<()> {
|
||||||
|
let temp_dir = assert_fs::TempDir::new()?;
|
||||||
|
setup_gitconfig(temp_dir.path())?;
|
||||||
|
let repo = git2::Repository::init(temp_dir.path())?;
|
||||||
|
eprintln!("{:?}", repo.path());
|
||||||
|
let git_status = std::process::Command::new("git")
|
||||||
|
.args(["status"])
|
||||||
|
.current_dir(temp_dir.path())
|
||||||
|
.spawn()
|
||||||
|
.context("git status")?
|
||||||
|
.wait()
|
||||||
|
.context("didn't complete")?;
|
||||||
|
eprintln!("{}", git_status);
|
||||||
|
let git_config = std::process::Command::new("git")
|
||||||
|
.args(["config", "--list"])
|
||||||
|
.current_dir(temp_dir.path())
|
||||||
|
.spawn()
|
||||||
|
.context("git status")?
|
||||||
|
.wait()
|
||||||
|
.context("didn't complete")?;
|
||||||
|
eprintln!("{}", git_config);
|
||||||
|
let git_config = std::process::Command::new("git")
|
||||||
|
.args(["config", "--list", "--local"])
|
||||||
|
.current_dir(temp_dir.path())
|
||||||
|
.spawn()
|
||||||
|
.context("git status")?
|
||||||
|
.wait()
|
||||||
|
.context("didn't complete")?;
|
||||||
|
eprintln!("{}", git_config);
|
||||||
|
Err(anyhow::anyhow!("finished (error for debug)"))
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn single_device() -> Result<()> {
|
fn single_device() -> Result<()> {
|
||||||
let config_dir = assert_fs::TempDir::new()?;
|
let config_dir = assert_fs::TempDir::new()?;
|
||||||
|
@ -257,7 +291,6 @@ mod integrated_test {
|
||||||
//
|
//
|
||||||
// devices: first, second
|
// devices: first, second
|
||||||
let config_dir_2 = assert_fs::TempDir::new()?;
|
let config_dir_2 = assert_fs::TempDir::new()?;
|
||||||
setup_gitconfig(&config_dir_2)?;
|
|
||||||
let mut cmd2 = Command::cargo_bin("xdbm")?;
|
let mut cmd2 = Command::cargo_bin("xdbm")?;
|
||||||
cmd2.arg("-c")
|
cmd2.arg("-c")
|
||||||
.arg(config_dir_2.path())
|
.arg(config_dir_2.path())
|
||||||
|
|
Loading…
Add table
Reference in a new issue