1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#![feature(adt_const_params)]

mod remote;
mod local;

pub use local::LocalRepository;
pub use remote::{GitEERepository, GitHubRepository};
pub use git2::{Signature, Cred};
pub use git2;

#[cfg(test)]
mod tests {
    use super::*;
    use git2::{Signature, Cred};
    use std::fs::File;
    use std::io::Write;
    
    #[test]
    fn fuck() {
        std::fs::remove_dir_all("./lab2").unwrap();
        let github_repo = GitHubRepository {
            owner: "longfangsong".to_string(),
            name: "lab2".to_string(),
        };
        let mut repo = github_repo
            .clone(
                "./lab2",
                Some(|| {
                    Cred::userpass_plaintext(
                        "baipiao-bot",
                        "07b497cd5e083fe53080f8b5eccdd588e3286c5a",
                    )
                }),
            )
            .unwrap();

        repo.pull(
            "patch-1",
            Some(|| {
                Cred::userpass_plaintext("baipiao-bot", "07b497cd5e083fe53080f8b5eccdd588e3286c5a")
            }),
        )
        .unwrap();

        let mut f = File::create("./lab2/new4.txt").unwrap();
        f.write_all("hello".as_bytes()).unwrap();
        drop(f);

        let tree_id = repo.add_all().unwrap();

        let signature = Signature::now("baipiao-bot", "moss_the_bot@163.com").unwrap();
        repo.commit(tree_id, "test", signature).unwrap();
        repo.push(
            || Cred::userpass_plaintext("baipiao-bot", "07b497cd5e083fe53080f8b5eccdd588e3286c5a"),
            "patch-1",
        );
    }
}