@@ -5,6 +5,7 @@ use anyhow::Context;
5
5
use chrono:: Utc ;
6
6
use diesel:: prelude:: * ;
7
7
use std:: fs:: { self , OpenOptions } ;
8
+ use std:: process:: Command ;
8
9
use swirl:: PerformError ;
9
10
10
11
#[ swirl:: background_job]
@@ -98,37 +99,18 @@ pub fn squash_index(env: &Environment) -> Result<(), PerformError> {
98
99
99
100
// Shell out to git because libgit2 does not currently support push leases
100
101
101
- let temp_key_path = repo. credentials . write_temporary_ssh_key ( ) ?;
102
-
103
- let checkout_path = repo. checkout_path . path ( ) ;
104
- let output = std:: process:: Command :: new ( "git" )
105
- . current_dir ( checkout_path)
106
- . env (
107
- "GIT_SSH_COMMAND" ,
108
- format ! (
109
- "ssh -o StrictHostKeyChecking=accept-new -i {}" ,
110
- temp_key_path. display( )
111
- ) ,
112
- )
113
- . args ( & [
114
- "push" ,
115
- // Both updates should succeed or fail together
116
- "--atomic" ,
117
- "origin" ,
118
- // Overwrite master, but only if it server matches the expected value
119
- & format ! ( "--force-with-lease=refs/heads/master:{}" , original_head) ,
120
- // The new squashed commit is pushed to master
121
- "HEAD:refs/heads/master" ,
122
- // The previous value of HEAD is pushed to a snapshot branch
123
- & format ! ( "{}:refs/heads/snapshot-{}" , original_head, now) ,
124
- ] )
125
- . output ( ) ?;
126
-
127
- if !output. status . success ( ) {
128
- let stderr = String :: from_utf8_lossy ( & output. stderr ) ;
129
- let message = format ! ( "Running git command failed with: {}" , stderr) ;
130
- return Err ( message. into ( ) ) ;
131
- }
102
+ repo. run_command ( Command :: new ( "git" ) . args ( & [
103
+ "push" ,
104
+ // Both updates should succeed or fail together
105
+ "--atomic" ,
106
+ "origin" ,
107
+ // Overwrite master, but only if it server matches the expected value
108
+ & format ! ( "--force-with-lease=refs/heads/master:{}" , original_head) ,
109
+ // The new squashed commit is pushed to master
110
+ "HEAD:refs/heads/master" ,
111
+ // The previous value of HEAD is pushed to a snapshot branch
112
+ & format ! ( "{}:refs/heads/snapshot-{}" , original_head, now) ,
113
+ ] ) ) ?;
132
114
133
115
println ! ( "The index has been successfully squashed." ) ;
134
116
0 commit comments