1
1
package commands
2
2
3
3
import (
4
+ "fmt"
4
5
"github.com/hawser/git-hawser/git"
5
6
"github.com/hawser/git-hawser/hawser"
7
+ "github.com/hawser/git-hawser/pointer"
6
8
"github.com/hawser/git-hawser/scanner"
7
9
"github.com/rubyist/tracerx"
8
10
"github.com/spf13/cobra"
9
11
"io/ioutil"
10
12
"os"
13
+ "path/filepath"
11
14
"strings"
12
15
)
13
16
@@ -138,6 +141,10 @@ func pushAsset(oid, filename string, index, totalFiles int) *hawser.WrappedError
138
141
return hawser .Errorf (err , "Error uploading file %s (%s)" , filename , oid )
139
142
}
140
143
144
+ if err := ensureFile (filename , path ); err != nil {
145
+ return hawser .Errorf (err , "Error uploading file %s (%s)" , filename , oid )
146
+ }
147
+
141
148
cb , file , cbErr := hawser .CopyCallbackFile ("push" , filename , index , totalFiles )
142
149
if cbErr != nil {
143
150
Error (cbErr .Error ())
@@ -150,6 +157,41 @@ func pushAsset(oid, filename string, index, totalFiles int) *hawser.WrappedError
150
157
return hawser .Upload (path , filename , cb )
151
158
}
152
159
160
+ // ensureFile makes sure that the cleanPath exists before pushing it. If it
161
+ // does not exist, it attempts to clean it by reading the file at smudgePath.
162
+ func ensureFile (smudgePath , cleanPath string ) error {
163
+ if _ , err := os .Stat (cleanPath ); err == nil {
164
+ return nil
165
+ }
166
+
167
+ expectedOid := filepath .Base (cleanPath )
168
+ localPath := filepath .Join (hawser .LocalWorkingDir , smudgePath )
169
+ file , err := os .Open (localPath )
170
+ if err != nil {
171
+ return err
172
+ }
173
+
174
+ defer file .Close ()
175
+
176
+ stat , err := file .Stat ()
177
+ if err != nil {
178
+ return err
179
+ }
180
+
181
+ cleaned , err := pointer .Clean (file , stat .Size (), nil )
182
+ if err != nil {
183
+ return err
184
+ }
185
+
186
+ cleaned .Close ()
187
+
188
+ if expectedOid != cleaned .Oid {
189
+ return fmt .Errorf ("Expected %s to have an OID of %s, got %s" , smudgePath , expectedOid , cleaned .Oid )
190
+ }
191
+
192
+ return nil
193
+ }
194
+
153
195
// decodeRefs pulls the sha1s out of the line read from the pre-push
154
196
// hook's stdin.
155
197
func decodeRefs (input string ) (string , string ) {
0 commit comments