File tree Expand file tree Collapse file tree 3 files changed +15
-14
lines changed Expand file tree Collapse file tree 3 files changed +15
-14
lines changed Original file line number Diff line number Diff line change @@ -955,15 +955,12 @@ pub fn fetch(
955
955
gctx : & GlobalContext ,
956
956
remote_kind : RemoteKind ,
957
957
) -> CargoResult < ( ) > {
958
- if gctx. frozen ( ) {
958
+ if let Some ( offline_flag ) = gctx. offline_flag ( ) {
959
959
anyhow:: bail!(
960
- "attempting to update a git repository, but --frozen \
960
+ "attempting to update a git repository, but {offline_flag} \
961
961
was specified"
962
962
)
963
963
}
964
- if !gctx. network_allowed ( ) {
965
- anyhow:: bail!( "can't update a git repository in the offline mode" )
966
- }
967
964
968
965
let shallow = remote_kind. to_shallow_setting ( repo. is_shallow ( ) , gctx) ;
969
966
Original file line number Diff line number Diff line change @@ -1161,7 +1161,17 @@ impl GlobalContext {
1161
1161
}
1162
1162
1163
1163
pub fn network_allowed ( & self ) -> bool {
1164
- !self . frozen ( ) && !self . offline ( )
1164
+ !self . offline_flag ( ) . is_some ( )
1165
+ }
1166
+
1167
+ pub fn offline_flag ( & self ) -> Option < & ' static str > {
1168
+ if self . frozen {
1169
+ Some ( "--frozen" )
1170
+ } else if self . offline {
1171
+ Some ( "--offline" )
1172
+ } else {
1173
+ None
1174
+ }
1165
1175
}
1166
1176
1167
1177
pub fn offline ( & self ) -> bool {
Original file line number Diff line number Diff line change @@ -25,15 +25,9 @@ pub fn http_handle(gctx: &GlobalContext) -> CargoResult<Easy> {
25
25
}
26
26
27
27
pub fn http_handle_and_timeout ( gctx : & GlobalContext ) -> CargoResult < ( Easy , HttpTimeout ) > {
28
- if gctx. frozen ( ) {
28
+ if let Some ( offline_flag ) = gctx. offline_flag ( ) {
29
29
bail ! (
30
- "attempting to make an HTTP request, but --frozen was \
31
- specified"
32
- )
33
- }
34
- if gctx. offline ( ) {
35
- bail ! (
36
- "attempting to make an HTTP request, but --offline was \
30
+ "attempting to make an HTTP request, but {offline_flag} was \
37
31
specified"
38
32
)
39
33
}
You can’t perform that action at this time.
0 commit comments