@@ -3,11 +3,14 @@ use git2::{DiffOptions, Repository, StatusOptions};
33use std:: io;
44use std:: io:: ErrorKind ;
55use std:: path:: { Path , PathBuf } ;
6+ use std:: process:: { Command , Stdio } ;
67use std:: sync:: mpsc;
78use std:: sync:: mpsc:: Sender ;
89use threadpool:: ThreadPool ;
910use walkdir:: WalkDir ;
1011
12+ use crate :: utils:: find_binary_path;
13+
1114// Check if a directory should be excluded
1215fn is_excluded_dir ( entry : & walkdir:: DirEntry , exclude_dirs : & [ String ] ) -> bool {
1316 let path = entry. path ( ) ; // Get the full path of the directory
@@ -67,6 +70,27 @@ pub fn check_untracked_files(repo_path: &Path) -> Result<Vec<String>, git2::Erro
6770 Ok ( untracked_files)
6871}
6972
73+ // Pull changes in a Git repository
74+ // TODO: use git2 library instead of command process, like the rest of the code
75+ pub fn pull_changes ( repo_path : & Path ) -> Result < String , io:: Error > {
76+ let git_path = find_binary_path ( "git" ) . unwrap_or_else ( |_| "/usr/bin/git" . into ( ) ) ;
77+
78+ // Ejecutar git pull en el directorio correcto
79+ let output = Command :: new ( git_path)
80+ . arg ( "pull" )
81+ . current_dir ( repo_path)
82+ . stdout ( Stdio :: piped ( ) )
83+ . stderr ( Stdio :: piped ( ) )
84+ . output ( ) ?;
85+
86+ if output. status . success ( ) {
87+ Ok ( String :: from_utf8_lossy ( & output. stdout ) . into_owned ( ) )
88+ } else {
89+ let error_msg = String :: from_utf8_lossy ( & output. stderr ) ;
90+ Err ( io:: Error :: new ( ErrorKind :: Other , error_msg. to_string ( ) ) )
91+ }
92+ }
93+
7094// Show the diff for a specific file in a Git repository
7195pub fn show_diff ( repo_path : & Path , file : & str ) -> io:: Result < String > {
7296 let repo = Repository :: open ( repo_path) . expect ( "Error opening repository" ) ;
0 commit comments