@@ -83,6 +83,8 @@ public function generatePatch(array $originalFiles, array $newFiles): RecipePatc
83
83
}
84
84
}
85
85
86
+ // Use git binary to get project path from repository root
87
+ $ prefix = trim ($ this ->execute ('git rev-parse --show-prefix ' , $ this ->rootDir ));
86
88
$ tmpPath = sys_get_temp_dir ().'/_flex_recipe_update ' .uniqid (mt_rand (), true );
87
89
$ this ->filesystem ->mkdir ($ tmpPath );
88
90
@@ -104,7 +106,7 @@ public function generatePatch(array $originalFiles, array $newFiles): RecipePatc
104
106
$ this ->writeFiles ($ newFiles , $ tmpPath );
105
107
$ this ->execute ('git add -A ' , $ tmpPath );
106
108
107
- $ patchString = $ this ->execute ('git diff --cached ' , $ tmpPath );
109
+ $ patchString = $ this ->execute (sprintf ( 'git diff --cached --src-prefix "a/%s" --dst-prefix "b/%s" ' , $ prefix , $ prefix ) , $ tmpPath );
108
110
$ removedPatches = [];
109
111
$ patchString = DiffHelper::removeFilesFromPatch ($ patchString , $ deletedModifiedFiles , $ removedPatches );
110
112
@@ -166,8 +168,9 @@ private function execute(string $command, string $cwd): string
166
168
private function addMissingBlobs (array $ blobs ): array
167
169
{
168
170
$ addedBlobs = [];
171
+ $ gitDir = trim ($ this ->execute ('git rev-parse --absolute-git-dir ' , $ this ->rootDir ));
169
172
foreach ($ blobs as $ hash => $ contents ) {
170
- $ blobPath = $ this -> rootDir .'/ ' .$ this ->getBlobPath ($ hash );
173
+ $ blobPath = $ gitDir .'/ ' .$ this ->getBlobPath ($ hash );
171
174
if (file_exists ($ blobPath )) {
172
175
continue ;
173
176
}
@@ -185,14 +188,15 @@ private function addMissingBlobs(array $blobs): array
185
188
private function generateBlobs (array $ originalFiles , string $ originalFilesRoot ): array
186
189
{
187
190
$ addedBlobs = [];
191
+ $ originalFilesGitDir = trim ($ this ->execute ('git rev-parse --absolute-git-dir ' , $ originalFilesRoot ));
188
192
foreach ($ originalFiles as $ filename => $ contents ) {
189
193
// if the file didn't originally exist, no blob needed
190
194
if (!file_exists ($ originalFilesRoot .'/ ' .$ filename )) {
191
195
continue ;
192
196
}
193
197
194
198
$ hash = trim ($ this ->execute ('git hash-object ' .ProcessExecutor::escape ($ filename ), $ originalFilesRoot ));
195
- $ addedBlobs [$ hash ] = file_get_contents ($ originalFilesRoot .'/ ' .$ this ->getBlobPath ($ hash ));
199
+ $ addedBlobs [$ hash ] = file_get_contents ($ originalFilesGitDir .'/ ' .$ this ->getBlobPath ($ hash ));
196
200
}
197
201
198
202
return $ addedBlobs ;
@@ -203,7 +207,7 @@ private function getBlobPath(string $hash): string
203
207
$ hashStart = substr ($ hash , 0 , 2 );
204
208
$ hashEnd = substr ($ hash , 2 );
205
209
206
- return '.git/ objects/ ' .$ hashStart .'/ ' .$ hashEnd ;
210
+ return 'objects/ ' .$ hashStart .'/ ' .$ hashEnd ;
207
211
}
208
212
209
213
private function _applyPatchFile (RecipePatch $ patch )
0 commit comments