@@ -78,22 +78,13 @@ pub fn rev_exists(rev: &str, git_dir: Option<&Path>) -> Result<bool, String> {
7878/// We will then fall back to origin/master in the hope that at least this exists.
7979pub fn updated_master_branch ( git_dir : Option < & Path > ) -> Result < String , String > {
8080 let upstream_remote = get_rust_lang_rust_remote ( git_dir) ?;
81- for upstream_master in [ format ! ( "{upstream_remote}/master" ) , format ! ( "origin/master" ) ] {
82- if rev_exists ( & upstream_master, git_dir) ? {
83- return Ok ( upstream_master) ;
84- }
81+ let upstream_master = format ! ( "{upstream_remote}/master" ) ;
82+ if rev_exists ( & upstream_master, git_dir) ? {
83+ return Ok ( upstream_master) ;
8584 }
8685
87- Err ( format ! ( "Cannot find any suitable upstream master branch" ) )
88- }
89-
90- pub fn get_git_merge_base ( git_dir : Option < & Path > ) -> Result < String , String > {
91- let updated_master = updated_master_branch ( git_dir) ?;
92- let mut git = Command :: new ( "git" ) ;
93- if let Some ( git_dir) = git_dir {
94- git. current_dir ( git_dir) ;
95- }
96- Ok ( output_result ( git. arg ( "merge-base" ) . arg ( & updated_master) . arg ( "HEAD" ) ) ?. trim ( ) . to_owned ( ) )
86+ // We could implement smarter logic here in the future.
87+ Ok ( "origin/master" . into ( ) )
9788}
9889
9990/// Returns the files that have been modified in the current branch compared to the master branch.
@@ -103,13 +94,20 @@ pub fn get_git_modified_files(
10394 git_dir : Option < & Path > ,
10495 extensions : & Vec < & str > ,
10596) -> Result < Option < Vec < String > > , String > {
106- let merge_base = get_git_merge_base ( git_dir) ?;
97+ let Ok ( updated_master) = updated_master_branch ( git_dir) else {
98+ return Ok ( None ) ;
99+ } ;
107100
108- let mut git = Command :: new ( "git" ) ;
109- if let Some ( git_dir) = git_dir {
110- git. current_dir ( git_dir) ;
111- }
112- let files = output_result ( git. args ( [ "diff-index" , "--name-only" , merge_base. trim ( ) ] ) ) ?
101+ let git = || {
102+ let mut git = Command :: new ( "git" ) ;
103+ if let Some ( git_dir) = git_dir {
104+ git. current_dir ( git_dir) ;
105+ }
106+ git
107+ } ;
108+
109+ let merge_base = output_result ( git ( ) . arg ( "merge-base" ) . arg ( & updated_master) . arg ( "HEAD" ) ) ?;
110+ let files = output_result ( git ( ) . arg ( "diff-index" ) . arg ( "--name-only" ) . arg ( merge_base. trim ( ) ) ) ?
113111 . lines ( )
114112 . map ( |s| s. trim ( ) . to_owned ( ) )
115113 . filter ( |f| {
0 commit comments