@@ -11,6 +11,19 @@ const JOSH_FILTER: &str = ":/src/doc/rustc-dev-guide";
11
11
const JOSH_PORT : u16 = 42042 ;
12
12
const UPSTREAM_REPO : & str = "rust-lang/rust" ;
13
13
14
+ pub enum RustcPullError {
15
+ /// No changes are available to be pulled.
16
+ NothingToPull ,
17
+ /// A rustc-pull has failed, probably a git operation error has occurred.
18
+ PullFailed ( anyhow:: Error )
19
+ }
20
+
21
+ impl < E > From < E > for RustcPullError where E : Into < anyhow:: Error > {
22
+ fn from ( error : E ) -> Self {
23
+ Self :: PullFailed ( error. into ( ) )
24
+ }
25
+ }
26
+
14
27
pub struct GitSync {
15
28
dir : PathBuf ,
16
29
}
@@ -24,7 +37,7 @@ impl GitSync {
24
37
} )
25
38
}
26
39
27
- pub fn rustc_pull ( & self , commit : Option < String > ) -> anyhow :: Result < ( ) > {
40
+ pub fn rustc_pull ( & self , commit : Option < String > ) -> Result < ( ) , RustcPullError > {
28
41
let sh = Shell :: new ( ) ?;
29
42
sh. change_dir ( & self . dir ) ;
30
43
let commit = commit. map ( Ok ) . unwrap_or_else ( || {
@@ -38,7 +51,7 @@ impl GitSync {
38
51
} ) ?;
39
52
// Make sure the repo is clean.
40
53
if cmd ! ( sh, "git status --untracked-files=no --porcelain" ) . read ( ) ?. is_empty ( ) . not ( ) {
41
- bail ! ( "working directory must be clean before performing rustc pull" ) ;
54
+ return Err ( anyhow :: anyhow !( "working directory must be clean before performing rustc pull" ) . into ( ) ) ;
42
55
}
43
56
// Make sure josh is running.
44
57
let josh = Self :: start_josh ( ) ?;
@@ -47,7 +60,7 @@ impl GitSync {
47
60
48
61
let previous_base_commit = sh. read_file ( "rust-version" ) ?. trim ( ) . to_string ( ) ;
49
62
if previous_base_commit == commit {
50
- return Err ( anyhow :: anyhow! ( "No changes since last pull" ) ) ;
63
+ return Err ( RustcPullError :: NothingToPull ) ;
51
64
}
52
65
53
66
// Update rust-version file. As a separate commit, since making it part of
@@ -94,12 +107,13 @@ impl GitSync {
94
107
cmd ! ( sh, "git reset --hard HEAD^" )
95
108
. run ( )
96
109
. expect ( "FAILED to clean up after creating the preparation commit" ) ;
97
- return Err ( anyhow:: anyhow!( "No merge was performed, nothing to pull. Rolled back the preparation commit." ) ) ;
110
+ eprintln ! ( "No merge was performed, no changes to pull were found. Rolled back the preparation commit." ) ;
111
+ return Err ( RustcPullError :: NothingToPull ) ;
98
112
}
99
113
100
114
// Check that the number of roots did not increase.
101
115
if num_roots ( ) ? != num_roots_before {
102
- bail ! ( "Josh created a new root commit. This is probably not the history you want." ) ;
116
+ return Err ( anyhow :: anyhow !( "Josh created a new root commit. This is probably not the history you want." ) . into ( ) ) ;
103
117
}
104
118
105
119
drop ( josh) ;
0 commit comments