Skip to content

Commit 27d0885

Browse files
committed
dev: added new colors for pushing to git
1 parent 65210a1 commit 27d0885

1 file changed

Lines changed: 68 additions & 2 deletions

File tree

src/modules/git/git.rs

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1+
use crate::cli::GitArgs;
12
use colored::Colorize;
23
use std::process::{Command, Output};
34

4-
use crate::cli::GitArgs;
5-
65
fn execute_git_command(args: &[&str]) -> Result<Output, std::io::Error> {
76
Command::new("git").args(args).output()
87
}
@@ -12,7 +11,70 @@ fn is_commit_successful(output: &Output) -> bool {
1211
stderr.is_empty() || stderr.contains("[") || stderr.contains("]")
1312
}
1413

14+
fn get_changed_files() -> Result<(Vec<String>, Vec<String>, Vec<String>), std::io::Error> {
15+
let output = Command::new("git")
16+
.args(&["status", "--porcelain"])
17+
.output()?;
18+
19+
let status = String::from_utf8_lossy(&output.stdout);
20+
let mut modified = Vec::new();
21+
let mut added = Vec::new();
22+
let mut deleted = Vec::new();
23+
24+
for line in status.lines() {
25+
if line.len() >= 3 {
26+
let status = &line[..2];
27+
let file = line[3..].trim().to_string();
28+
29+
match status {
30+
s if s.contains('M') => modified.push(file),
31+
s if s.contains('A') => added.push(file),
32+
s if s.contains('D') => deleted.push(file),
33+
_ => {}
34+
}
35+
}
36+
}
37+
38+
Ok((modified, added, deleted))
39+
}
40+
41+
fn print_changes(modified: &[String], added: &[String], deleted: &[String]) {
42+
if !modified.is_empty() {
43+
println!("\n{} Modified files:", "↻".yellow());
44+
for file in modified {
45+
println!(" {}", file.yellow());
46+
}
47+
}
48+
49+
if !added.is_empty() {
50+
println!("\n{} Added files:", "+".green());
51+
for file in added {
52+
println!(" {}", file.green());
53+
}
54+
}
55+
56+
if !deleted.is_empty() {
57+
println!("\n{} Deleted files:", "-".red());
58+
for file in deleted {
59+
println!(" {}", file.red());
60+
}
61+
}
62+
63+
let total = modified.len() + added.len() + deleted.len();
64+
println!("\n{} Total changes: {}", "ℹ".blue(), total);
65+
}
66+
1567
pub fn handle(args: GitArgs) {
68+
// Получаем список изменений ДО выполнения операций
69+
let changes_result = get_changed_files();
70+
let (modified, added, deleted) = match changes_result {
71+
Ok(changes) => changes,
72+
Err(e) => {
73+
eprintln!("{} Failed to get changed files: {}", "❌".red(), e);
74+
return;
75+
}
76+
};
77+
1678
if args.add {
1779
match execute_git_command(&["add", "."]) {
1880
Ok(output) if output.status.success() => {
@@ -29,6 +91,9 @@ pub fn handle(args: GitArgs) {
2991
}
3092
}
3193

94+
// Выводим изменения перед коммитом
95+
print_changes(&modified, &added, &deleted);
96+
3297
let commit_output = execute_git_command(&["commit", "-m", &args.message]);
3398
match commit_output {
3499
Ok(output) if is_commit_successful(&output) => {
@@ -62,6 +127,7 @@ pub fn handle(args: GitArgs) {
62127
match execute_git_command(&["push"]) {
63128
Ok(output) if output.status.success() => {
64129
println!("{}", "✅ Pushed successfully".green());
130+
println!("\n{} Commit message: {}", "✏️".cyan(), args.message.cyan());
65131
}
66132
Ok(output) => {
67133
let error_msg = String::from_utf8_lossy(&output.stderr);

0 commit comments

Comments
 (0)