pijul 0.7.2

A patch-based distributed version control system, easy to use and fast. Command-line interface.
use {thrussh, thrussh_keys, libpijul, hyper, rustyline, term, toml, hex, base64, ring};
use std;
use std::path::PathBuf;

error_chain!{
    foreign_links {
        IO(std::io::Error);
        Rustyline(rustyline::error::ReadlineError);
        Term(term::Error);
        Repository(libpijul::Error);
        UTF8(std::string::FromUtf8Error);
        Hex(hex::FromHexError);
        SSH(thrussh::Error);
        SSHKeys(thrussh_keys::Error);
        Hyper(hyper::error::Error);
        TomlDe(toml::de::Error);
        TomlSer(toml::ser::Error);
        Base64(base64::DecodeError);
        Ring(ring::error::Unspecified);
    }
    errors {
        InARepository(path: std::path::PathBuf) {
            description("Inside repository")
                display("Inside repository {:?}", path)
        }
        NotInARepository {
            description("Not in a repository")
        }
        MissingRemoteRepository {
            description("Missing remote repository")
        }
        InvalidPath(path: String) {
            description("Invalid path")
                display("Invalid path {}", path)
        }
        WrongHash {
            description("Wrong hash")
        }
        BranchAlreadyExists {
            description("That branch already exists")
        }
        CannotDeleteCurrentBranch {
            description("Cannot delete current branch")
        }
        NoSuchBranch {
            description("No such branch")
        }
        IsDirectory {
            description("Is a directory")
        }
        CannotParseRemote {
            description("Cannot parse remote address")
        }
        WillNotOverwriteKeyFile(path: std::path::PathBuf) {
            description("Refusing to overwrite key file")
                display("Refusing to overwrite key file {:?}", path)
        }
        BranchDoesNotHavePatch(branch_name: String, patch: libpijul::Hash) {
            description("This branch does not have this patch")
                display("Branch \"{}\" does not have patch {}",
                        branch_name,
                        patch.to_base64(base64::URL_SAFE_NO_PAD))
        }
        PatchNotFound(repo_root: String, patch_hash: libpijul::Hash) {
            description("Patch not found")
                display("Patch {} not found in repository {}",
                        patch_hash.to_base64(base64::URL_SAFE_NO_PAD),
                        repo_root)
        }
        SshKeyNotFound(path: PathBuf) {
            description("SSH key not found")
                display("SSH key not found in {:?}", path)
        }
    }
}

impl ErrorKind {
    pub fn lacks_space(&self) -> bool {
        match *self {
            ErrorKind::Repository(ref r) => r.lacks_space(),
            _ => false
        }
    }
}

impl From<thrussh::HandlerError<Error>> for Error {
    fn from(err: thrussh::HandlerError<Error>) -> Error {
        match err {
            thrussh::HandlerError::Handler(e) => e,
            thrussh::HandlerError::Error(e) => ErrorKind::SSH(e).into()
        }
    }
}
impl From<Error> for thrussh::HandlerError<Error> {
    fn from(e: Error) -> thrussh::HandlerError<Error> {
        thrussh::HandlerError::Handler(e)
    }
}