step fourty six: show changed files
This commit is contained in:
parent
4387831290
commit
84bb97e1a2
23
src/diff.rs
23
src/diff.rs
|
@ -67,3 +67,26 @@ pub fn diff_trees(t_from: HashMap<String, String>, t_to: HashMap<String, String>
|
|||
|
||||
return output;
|
||||
}
|
||||
|
||||
pub fn changed_files(
|
||||
t_from: HashMap<String, String>,
|
||||
t_to: HashMap<String, String>,
|
||||
) -> Vec<(String, String)> {
|
||||
let mut result = vec![];
|
||||
let trees = vec![t_from, t_to];
|
||||
for (path, oids) in compare_trees(trees).iter() {
|
||||
let o_from = oids[0].clone();
|
||||
let o_to = oids[1].clone();
|
||||
if o_from != o_to {
|
||||
let action = if o_from == "" {
|
||||
"new file"
|
||||
} else if o_to == "" {
|
||||
"deleted"
|
||||
} else {
|
||||
"mofified"
|
||||
};
|
||||
result.push((path.clone(), action.to_owned()))
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
12
src/main.rs
12
src/main.rs
|
@ -252,10 +252,20 @@ fn branch(matches: ArgMatches) {
|
|||
|
||||
fn status() {
|
||||
let branch = base::get_branch_name();
|
||||
let head = base::get_oid("@".to_owned());
|
||||
if branch != "".to_owned() {
|
||||
println!("On branch {}", branch);
|
||||
} else {
|
||||
println!("HEAD detached at {}", &base::get_oid("@".to_owned())[1..10])
|
||||
println!("HEAD detached at {}", &head[1..10])
|
||||
}
|
||||
|
||||
println!("Changes to be committed:\n");
|
||||
let head_commit = base::get_commit(head);
|
||||
for (path, action) in diff::changed_files(
|
||||
base::get_tree(head_commit.tree, "".to_owned()),
|
||||
base::get_working_tree(),
|
||||
) {
|
||||
println!("{:>12}: {}", action, path);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue