Generate README on behalf of user.
parent
37394588e5
commit
d23fcadcc1
|
@ -274,7 +274,7 @@ mod tests {
|
|||
env::set_var("HOME", &home_dir);
|
||||
env::set_var("XDG_CONFIG_HOME", "");
|
||||
|
||||
let template = path::resolve(Path::new("examples/template.yml")).unwrap();
|
||||
let template = path::resolve(Path::new("rsrc/template.yml")).unwrap();
|
||||
let config = config::load(&vec![template]).unwrap();
|
||||
|
||||
func(&config, &home_dir);
|
||||
|
|
23
src/git.rs
23
src/git.rs
|
@ -5,7 +5,9 @@ use git2::{
|
|||
StashFlags,
|
||||
};
|
||||
use simplelog::{info, paris, warn};
|
||||
use std::{collections::HashSet, env::VarError, error, fmt, io, path::Path, result};
|
||||
use std::{
|
||||
collections::HashSet, env::VarError, error, fmt, fs::File, io, io::Write, path::Path, result,
|
||||
};
|
||||
|
||||
// ========================================
|
||||
// Error
|
||||
|
@ -133,6 +135,24 @@ pub fn init(pc: &PathConfig) -> Result<Repository> {
|
|||
// Syncing
|
||||
// ========================================
|
||||
|
||||
fn create_readme(repo: &Repository) -> Result<()> {
|
||||
let workdir = repo.workdir().ok_or(Error::InvalidBareRepo)?;
|
||||
|
||||
let mut readme = workdir.to_path_buf();
|
||||
readme.push("README.md");
|
||||
|
||||
let mut file = File::create(&readme)?;
|
||||
// TODO(jrpotter): Get the name of the remote repository.
|
||||
file.write_all(
|
||||
"# home-config\n\nThis repository is maintained by \
|
||||
[homesync](https://github.com/jrpotter/homesync)."
|
||||
.as_ref(),
|
||||
)?;
|
||||
info!("Generated new <cyan>README.md</> file.");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn push(pc: &PathConfig, repo: &mut Repository) -> Result<()> {
|
||||
// First pull to make sure there are no conflicts when we push our changes.
|
||||
// This will also perform validation and construct our local and remote
|
||||
|
@ -141,6 +161,7 @@ pub fn push(pc: &PathConfig, repo: &mut Repository) -> Result<()> {
|
|||
|
||||
let refspec = format!("refs/heads/{}", &pc.config.repos.remote.branch);
|
||||
repo.set_head(&refspec)?;
|
||||
create_readme(repo)?;
|
||||
|
||||
// The index corresponds to our staging area. We add all files and write out
|
||||
// to a tree. The resulting tree can be found using `git ls-tree <oid>`.
|
||||
|
|
Loading…
Reference in New Issue