Skip to content

Commit

Permalink
Merge branch 'merge-90272a39-8cac-4dde-9eb7-b203f4875906-JY6EOUUGM7MD…
Browse files Browse the repository at this point in the history
…RDQ2DO4X6NDP5FHXYANR'
  • Loading branch information
yrashk committed Nov 14, 2018
2 parents acaf05b + d7e5e17 commit d1d3b12
Show file tree
Hide file tree
Showing 13 changed files with 80 additions and 34 deletions.
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1 @@
../../records/OH/TO/NX/PT/BW/K2/R2/VP/4P/2G/LC/M4/WX/WL/6D/OHTONXPTBWK2R2VP4P2GLCM4WXWL6DFI
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1 @@
Yurii Rashkovskii <me@yrashk.com>
Original file line number Original file line Diff line number Diff line change
@@ -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-----
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1 @@
2018-11-14T08:50:14.487955707Z
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1 @@
JY6EOUUGM7MDRDQ2DO4X6NDP5FHXYANR
65 changes: 36 additions & 29 deletions sit/src/authorship.rs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,41 +4,48 @@ use atty;
use crate::cfg::{self, Configuration}; use crate::cfg::{self, Configuration};
use serde_json; use serde_json;


pub(crate) fn derive_authorship<P: AsRef<Path>>(config: &mut Configuration, config_path: P) -> i32 { pub(crate) fn derive_authorship<P: AsRef<Path>, P1: AsRef<Path>>(config: &mut Configuration, working_dir: P, config_path: P1) -> i32 {
if atty::is(atty::Stream::Stdin) { if config.author.is_none() {
println!("SIT needs your authorship identity to be configured\n"); let authorship = cfg::Author::from_gitconfig(working_dir.as_ref().join(".git").join("config"));
use question::{Question, Answer}; if authorship.is_some() {
let name = loop { config.author = authorship;
match Question::new("What is your name?").ask() { return 0;
None => continue, }
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)) => { Some(Answer::RESPONSE(value)) => {
if value.trim() == "" { if value.trim() == "" {
continue; None
} else { } else {
break value; Some(value)
} }
}, },
Some(answer) => panic!("Invalid answer {:?}", answer), Some(answer) => panic!("Invalid answer {:?}", answer),
} };
}; config.author = Some(cfg::Author { name, email });
let email = match Question::new("What is your e-mail address?").clarification("optional").ask() { let file =
None => None, fs::File::create(config_path).expect("can't open config file for writing");
Some(Answer::RESPONSE(value)) => { serde_json::to_writer_pretty(file, &config).expect("can't write config");
if value.trim() == "" { } else {
None eprintln!("SIT needs your authorship identity to be configured (supported sources: sit, git), or re-run this command in a terminal\n");
} else { return 1;
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;
} }
0 0
} }
2 changes: 1 addition & 1 deletion sit/src/command_record.rs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -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")) { if let Some(author) = cfg::Author::from_gitconfig(working_directory.as_ref().join(".git").join("config")) {
config.author = Some(author); config.author = Some(author);
} else { } 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 { if result != 0 {
return result; return result;
} }
Expand Down
5 changes: 3 additions & 2 deletions sit/src/command_web.rs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ use crate::cfg::Configuration;
use crate::authorship::derive_authorship; use crate::authorship::derive_authorship;
use std::path::{Path, PathBuf}; 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> { 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 { if result != 0 {
return result; return result;
} }
Expand Down
2 changes: 1 addition & 1 deletion sit/src/main.rs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ fn main_with_result(allow_external_subcommands: bool) -> i32 {
} }


if let Some(web_matches) = matches.subcommand_matches("web") { 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) { match command_external::command(&matches, repo, &cwd) {
Expand Down
19 changes: 18 additions & 1 deletion sit/tests/command_web.rs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -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")); 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.