@@ -81,14 +81,20 @@ func (p *PrebuildInitializer) Run(ctx context.Context, mappings []archive.IDMapp
81
81
82
82
// at this point we're actually a prebuild initialiser because we've been able to restore
83
83
// the prebuild.
84
+
84
85
src = csapi .WorkspaceInitFromPrebuild
85
86
86
87
// make sure we're on the correct branch
87
88
for _ , gi := range p .Git {
88
- err = runGitInit (ctx , gi )
89
+
90
+ commitChanged , err := runGitInit (ctx , gi )
89
91
if err != nil {
90
92
return src , err
91
93
}
94
+ if commitChanged {
95
+ // head commit has changed, so it's an outdated prebuild, which we treat as other
96
+ src = csapi .WorkspaceInitFromOther
97
+ }
92
98
}
93
99
log .Debug ("Initialized workspace with prebuilt snapshot" )
94
100
return
@@ -108,7 +114,7 @@ func clearWorkspace(location string) error {
108
114
return nil
109
115
}
110
116
111
- func runGitInit (ctx context.Context , gInit * GitInitializer ) (err error ) {
117
+ func runGitInit (ctx context.Context , gInit * GitInitializer ) (commitChanged bool , err error ) {
112
118
span , ctx := opentracing .StartSpanFromContext (ctx , "runGitInit" )
113
119
span .LogFields (
114
120
tracelog .String ("IsWorkingCopy" , fmt .Sprintf ("%v" , git .IsWorkingCopy (gInit .Location ))),
@@ -125,14 +131,25 @@ func runGitInit(ctx context.Context, gInit *GitInitializer) (err error) {
125
131
} else {
126
132
// git returned a non-zero exit code because of some reason we did not anticipate or an actual failure.
127
133
log .WithError (err ).WithField ("output" , string (out )).Error ("unexpected git stash error" )
128
- return xerrors .Errorf ("prebuild initializer: %w" , err )
134
+ return commitChanged , xerrors .Errorf ("prebuild initializer: %w" , err )
129
135
}
130
136
}
131
137
didStash := ! strings .Contains (string (out ), "No local changes to save" )
132
138
139
+ statusBefore , err := gInit .Status (ctx )
140
+ if err != nil {
141
+ log .WithError (err ).Warn ("couldn't run git status - continuing" )
142
+ }
133
143
err = checkGitStatus (gInit .realizeCloneTarget (ctx ))
134
144
if err != nil {
135
- return xerrors .Errorf ("prebuild initializer: %w" , err )
145
+ return commitChanged , xerrors .Errorf ("prebuild initializer: %w" , err )
146
+ }
147
+ statusAfter , err := gInit .Status (ctx )
148
+ if err != nil {
149
+ log .WithError (err ).Warn ("couldn't run git status - continuing" )
150
+ }
151
+ if statusBefore != nil && statusAfter != nil {
152
+ commitChanged = statusBefore .LatestCommit != statusAfter .LatestCommit
136
153
}
137
154
138
155
err = gInit .UpdateSubmodules (ctx )
@@ -173,5 +190,5 @@ func runGitInit(ctx context.Context, gInit *GitInitializer) (err error) {
173
190
return
174
191
}
175
192
}()
176
- return nil
193
+ return commitChanged , nil
177
194
}
0 commit comments