| 182 | } |
| 183 | |
| 184 | static int edit_patch(struct repository *repo, |
| 185 | int argc, |
| 186 | const char **argv, |
| 187 | const char *prefix) |
| 188 | { |
| 189 | char *file = repo_git_path(repo, "ADD_EDIT.patch"); |
| 190 | struct child_process child = CHILD_PROCESS_INIT; |
| 191 | struct rev_info rev; |
| 192 | int out; |
| 193 | struct stat st; |
| 194 | |
| 195 | repo_config(repo, git_diff_basic_config, NULL); |
| 196 | |
| 197 | if (repo_read_index(repo) < 0) |
| 198 | die(_("could not read the index")); |
| 199 | |
| 200 | repo_init_revisions(repo, &rev, prefix); |
| 201 | rev.diffopt.context = 7; |
| 202 | |
| 203 | argc = setup_revisions(argc, argv, &rev, NULL); |
| 204 | rev.diffopt.output_format = DIFF_FORMAT_PATCH; |
| 205 | rev.diffopt.use_color = GIT_COLOR_NEVER; |
| 206 | rev.diffopt.flags.ignore_dirty_submodules = 1; |
| 207 | out = xopen(file, O_CREAT | O_WRONLY | O_TRUNC, 0666); |
| 208 | rev.diffopt.file = xfdopen(out, "w"); |
| 209 | rev.diffopt.close_file = 1; |
| 210 | run_diff_files(&rev, 0); |
| 211 | |
| 212 | if (launch_editor(file, NULL, NULL)) |
| 213 | die(_("editing patch failed")); |
| 214 | |
| 215 | if (stat(file, &st)) |
| 216 | die_errno(_("could not stat '%s'"), file); |
| 217 | if (!st.st_size) |
| 218 | die(_("empty patch. aborted")); |
| 219 | |
| 220 | child.git_cmd = 1; |
| 221 | strvec_pushl(&child.args, "apply", "--recount", "--cached", file, |
| 222 | NULL); |
| 223 | if (run_command(&child)) |
| 224 | die(_("could not apply '%s'"), file); |
| 225 | |
| 226 | unlink(file); |
| 227 | free(file); |
| 228 | release_revisions(&rev); |
| 229 | return 0; |
| 230 | } |
| 231 | |
| 232 | static const char ignore_error[] = |
| 233 | N_("The following paths are ignored by one of your .gitignore files:\n"); |
no test coverage detected