diff --git a/examples/config.yml b/rsrc/example.yml similarity index 100% rename from examples/config.yml rename to rsrc/example.yml diff --git a/examples/template.yml b/rsrc/template.yml similarity index 100% rename from examples/template.yml rename to rsrc/template.yml diff --git a/src/copy.rs b/src/copy.rs index 9f90a59..ee1d8b9 100644 --- a/src/copy.rs +++ b/src/copy.rs @@ -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); diff --git a/src/git.rs b/src/git.rs index fc88b33..c4e2914 100644 --- a/src/git.rs +++ b/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 { // 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 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 `.