Permalink
Browse files

Merge branch 'merge-90272a39-8cac-4dde-9eb7-b203f4875906-JY6EOUUGM7MD…

…RDQ2DO4X6NDP5FHXYANR'
  • Loading branch information...
yrashk committed Nov 14, 2018
2 parents acaf05b + d7e5e17 commit d1d3b129e7100e0d1576751df2a23bac8dffec65
@@ -0,0 +1 @@
../../records/OH/TO/NX/PT/BW/K2/R2/VP/4P/2G/LC/M4/WX/WL/6D/OHTONXPTBWK2R2VP4P2GLCM4WXWL6DFI
@@ -0,0 +1,17 @@
-----BEGIN PGP SIGNATURE-----
iQJCBAABCAAsFiEEjmkaFOaskcs7s6g8HWDXz9gIRf8FAlvr4cYOHG1lQHlyYXNo
ay5jb20ACgkQHWDXz9gIRf8tcw/8DbLi6eYZvnbsiw9WYQ4CEklXwv6oaYXYrRIn
KHENBNilkOmZsDeJMckcyEDJubSO4DgBgylX7BlO+3IzROam1fMZX1Ux8yGx406x
dWFNho+b1nOidB+IzHQtZCkiGvDFHXCLMqllwiwc4OducVf0KxB2U2kFyX4AaB8s
g2kaSIhrbQlxA1syAv5yZXUrFHeDv9pE+NZZzZuynlBKMI7IraG8TS+NUP4rKcoI
ek/Vw3yHx/wxGm6uqEyGD+2z+M3OTtrM7kbS4zuJWvDCN/mEPqrhxZA0icex/jxo
G7/JErvWVoNVUZBExaYzN2SglxB7cdAIqWmm4l5NYlY3VYl7yKqZjux2DHckeEIM
tfy9yhpMODanRpdnwXBCUQ8FI+UC8qhx6t5Fdxya03I8MtbakYegP0YQhozw7xKV
L+bwkHnkfy3/5HyHl1r1AX/vuudNZGEmdnF3nqBT1BV6wlgfh+idMxiOS480gct8
a6OZ8Ft/x0mgeYAAJJWjKKdg+vzC8tG8ztkQ4IiYqls1h7Pa4kjQHbBPr3N4HoT8
TXnE0S6MiTubwAX++yvXUCq3asYLlcS+WHKjyKj7TM4tSWNSAZEhykapVhSdQOxX
81MQLtLKBv2RrDCfA8KWbLYbAZgAWwLYgYcrHRzKToc24VMFbwsRPUGXX20xuTcF
3C/gFU4=
=5zw5
-----END PGP SIGNATURE-----
@@ -4,41 +4,48 @@ use atty;
use crate::cfg::{self, Configuration};
use serde_json;
pub(crate) fn derive_authorship<P: AsRef<Path>>(config: &mut Configuration, config_path: P) -> i32 {
if atty::is(atty::Stream::Stdin) {
println!("SIT needs your authorship identity to be configured\n");
use question::{Question, Answer};
let name = loop {
match Question::new("What is your name?").ask() {
None => continue,
pub(crate) fn derive_authorship<P: AsRef<Path>, P1: AsRef<Path>>(config: &mut Configuration, working_dir: P, config_path: P1) -> i32 {
if config.author.is_none() {
let authorship = cfg::Author::from_gitconfig(working_dir.as_ref().join(".git").join("config"));
if authorship.is_some() {
config.author = authorship;
return 0;
}
if atty::is(atty::Stream::Stdin) {
println!("SIT needs your authorship identity to be configured\n");
use question::{Question, Answer};
let name = loop {
match Question::new("What is your name?").ask() {
None => continue,
Some(Answer::RESPONSE(value)) => {
if value.trim() == "" {
continue;
} else {
break value;
}
},
Some(answer) => panic!("Invalid answer {:?}", answer),
}
};
let email = match Question::new("What is your e-mail address?").clarification("optional").ask() {
None => None,
Some(Answer::RESPONSE(value)) => {
if value.trim() == "" {
continue;
None
} else {
break value;
Some(value)
}
},
Some(answer) => panic!("Invalid answer {:?}", answer),
}
};
let email = match Question::new("What is your e-mail address?").clarification("optional").ask() {
None => None,
Some(Answer::RESPONSE(value)) => {
if value.trim() == "" {
None
} else {
Some(value)
}
},
Some(answer) => panic!("Invalid answer {:?}", answer),
};
config.author = Some(cfg::Author { name, email });
let file =
fs::File::create(config_path).expect("can't open config file for writing");
serde_json::to_writer_pretty(file, &config).expect("can't write config");
} else {
eprintln!("SIT needs your authorship identity to be configured (supported sources: sit, git), or re-run this command in a terminal\n");
return 1;
};
config.author = Some(cfg::Author { name, email });
let file =
fs::File::create(config_path).expect("can't open config file for writing");
serde_json::to_writer_pretty(file, &config).expect("can't write config");
} else {
eprintln!("SIT needs your authorship identity to be configured (supported sources: sit, git), or re-run this command in a terminal\n");
return 1;
}
}
0
}
@@ -130,7 +130,7 @@ pub fn command<P: AsRef<Path>, P1: AsRef<Path>, MI>(matches: &ArgMatches, repo:
if let Some(author) = cfg::Author::from_gitconfig(working_directory.as_ref().join(".git").join("config")) {
config.author = Some(author);
} else {
let result = derive_authorship(&mut config, config_path.as_ref());
let result = derive_authorship(&mut config, working_directory, config_path.as_ref());
if result != 0 {
return result;
}
@@ -4,10 +4,11 @@ use crate::cfg::Configuration;
use crate::authorship::derive_authorship;
use std::path::{Path, PathBuf};
pub fn command<MI: 'static + Send + Sync, P: AsRef<Path>>(repo: Repository<MI>, matches: &ArgMatches, main_matches: ArgMatches<'static>, mut config: Configuration, config_path: P) -> i32
pub fn command<MI: 'static + Send + Sync, P: AsRef<Path>, P1: AsRef<Path>>(repo: Repository<MI>, matches: &ArgMatches, main_matches: ArgMatches<'static>, mut config: Configuration,
working_dir: P, config_path: P1) -> i32
where MI: repository::ModuleIterator<PathBuf, repository::Error> {
{
let result = derive_authorship(&mut config, config_path.as_ref());
let result = derive_authorship(&mut config, working_dir, config_path.as_ref());
if result != 0 {
return result;
}
@@ -574,7 +574,7 @@ fn main_with_result(allow_external_subcommands: bool) -> i32 {
}
if let Some(web_matches) = matches.subcommand_matches("web") {
return command_web::command(repo, web_matches, matches.clone(), config, config_path);
return command_web::command(repo, web_matches, matches.clone(), config, canonical_working_dir, config_path);
}
match command_external::command(&matches, repo, &cwd) {
@@ -20,4 +20,21 @@ fn web_no_authorship_no_git() {
assert!(String::from_utf8(out).unwrap().contains("SIT needs your authorship identity to be configured"));
}
/// Should derive authorship from git if it is available
#[test]
fn web_no_authorship() {
let dir = TestDir::new("sit", "web_no_authorship");
dir.cmd()
.arg("init")
.expect_success();
no_user_config(&dir);
dir.create_file(".git/config", "[user]\nname=Test\nemail=test@test.com");
let out = dir.cmd()
.env("HOME", dir.path(".").to_str().unwrap()) // to ensure there are no configs
.env("USERPROFILE", dir.path(".").to_str().unwrap())
.args(&["web","-"])
.expect_failure().stderr;
// should fail because the socket address is invalid, but not the authorship
println!("{}", String::from_utf8(out.clone()).unwrap());
assert!(String::from_utf8(out).unwrap().contains("invalid socket address"));
}

0 comments on commit d1d3b12

Please sign in to comment.