()
| 10 | |
| 11 | impl GitChain { |
| 12 | pub fn init() -> Result<Self, Error> { |
| 13 | let name_of_current_executable = executable_name(); |
| 14 | |
| 15 | let repo = match Repository::discover(".") { |
| 16 | Ok(repo) => repo, |
| 17 | Err(ref e) |
| 18 | if e.class() == ErrorClass::Repository && e.code() == ErrorCode::NotFound => |
| 19 | { |
| 20 | eprintln!( |
| 21 | "{} Not a git repository (or any of the parent directories)", |
| 22 | "error:".red().bold() |
| 23 | ); |
| 24 | eprintln!( |
| 25 | "\n{} This command must be run inside a git repository.", |
| 26 | "hint:".yellow().bold() |
| 27 | ); |
| 28 | eprintln!( |
| 29 | "{} Run {} to create a new git repository.", |
| 30 | "hint:".yellow().bold(), |
| 31 | "git init".bold() |
| 32 | ); |
| 33 | process::exit(1); |
| 34 | } |
| 35 | Err(e) => return Err(e), |
| 36 | }; |
| 37 | |
| 38 | if repo.is_bare() { |
| 39 | eprintln!( |
| 40 | "Cannot run {} on bare git repository.", |
| 41 | name_of_current_executable |
| 42 | ); |
| 43 | process::exit(1); |
| 44 | } |
| 45 | |
| 46 | let git_chain = GitChain { |
| 47 | repo, |
| 48 | executable_name: name_of_current_executable, |
| 49 | }; |
| 50 | Ok(git_chain) |
| 51 | } |
| 52 | |
| 53 | pub fn get_current_branch_name(&self) -> Result<String, Error> { |
| 54 | let head = match self.repo.head() { |
nothing calls this directly
no test coverage detected