| 1367 | } |
| 1368 | |
| 1369 | static int stash_patch(struct stash_info *info, const struct pathspec *ps, |
| 1370 | struct strbuf *out_patch, int quiet, |
| 1371 | struct interactive_options *interactive_opts) |
| 1372 | { |
| 1373 | int ret = 0; |
| 1374 | struct child_process cp_diff_tree = CHILD_PROCESS_INIT; |
| 1375 | struct commit *head_commit; |
| 1376 | const struct object_id *head_tree; |
| 1377 | struct index_state istate = INDEX_STATE_INIT(the_repository); |
| 1378 | char *old_index_env = NULL, *old_repo_index_file; |
| 1379 | |
| 1380 | remove_path(stash_index_path.buf); |
| 1381 | |
| 1382 | head_commit = lookup_commit(the_repository, &info->b_commit); |
| 1383 | if (!head_commit || repo_parse_commit(the_repository, head_commit)) { |
| 1384 | ret = -1; |
| 1385 | goto done; |
| 1386 | } |
| 1387 | head_tree = get_commit_tree_oid(head_commit); |
| 1388 | if (!head_tree) { |
| 1389 | ret = -1; |
| 1390 | goto done; |
| 1391 | } |
| 1392 | |
| 1393 | if (create_index_from_tree(head_tree, stash_index_path.buf)) { |
| 1394 | ret = -1; |
| 1395 | goto done; |
| 1396 | } |
| 1397 | |
| 1398 | /* Find out what the user wants. */ |
| 1399 | old_repo_index_file = the_repository->index_file; |
| 1400 | the_repository->index_file = stash_index_path.buf; |
| 1401 | old_index_env = xstrdup_or_null(getenv(INDEX_ENVIRONMENT)); |
| 1402 | setenv(INDEX_ENVIRONMENT, the_repository->index_file, 1); |
| 1403 | |
| 1404 | ret = !!run_add_p(the_repository, ADD_P_STASH, interactive_opts, NULL, ps, 0); |
| 1405 | |
| 1406 | the_repository->index_file = old_repo_index_file; |
| 1407 | if (old_index_env && *old_index_env) |
| 1408 | setenv(INDEX_ENVIRONMENT, old_index_env, 1); |
| 1409 | else |
| 1410 | unsetenv(INDEX_ENVIRONMENT); |
| 1411 | FREE_AND_NULL(old_index_env); |
| 1412 | |
| 1413 | /* State of the working tree. */ |
| 1414 | if (write_index_as_tree(&info->w_tree, &istate, stash_index_path.buf, 0, |
| 1415 | NULL)) { |
| 1416 | ret = -1; |
| 1417 | goto done; |
| 1418 | } |
| 1419 | |
| 1420 | cp_diff_tree.git_cmd = 1; |
| 1421 | strvec_pushl(&cp_diff_tree.args, "diff-tree", "-p", "-U1", "HEAD", |
| 1422 | "--no-color", |
| 1423 | oid_to_hex(&info->w_tree), "--", NULL); |
| 1424 | if (pipe_command(&cp_diff_tree, NULL, 0, out_patch, 0, NULL, 0)) { |
| 1425 | ret = -1; |
| 1426 | goto done; |
no test coverage detected