Git fork

Merge branch 'ps/config-error'

Many codepaths forget to check return value from git_config_set();
the function is made to die() to make sure we do not proceed when
setting a configuration variable failed.

* ps/config-error:
config: rename git_config_set_or_die to git_config_set
config: rename git_config_set to git_config_set_gently
compat: die when unable to set core.precomposeunicode
sequencer: die on config error when saving replay opts
init-db: die on config errors when initializing empty repo
clone: die on config error in cmd_clone
remote: die on config error when manipulating remotes
remote: die on config error when setting/adding branches
remote: die on config error when setting URL
submodule--helper: die on config error when cloning module
submodule: die on config error when linking modules
branch: die on config error when editing branch description
branch: die on config error when unsetting upstream
branch: report errors in tracking branch setup
config: introduce set_or_die wrappers

+159 -105
+36 -14
branch.c
··· 49 return 0; 50 } 51 52 - void install_branch_config(int flag, const char *local, const char *origin, const char *remote) 53 { 54 const char *shortname = NULL; 55 struct strbuf key = STRBUF_INIT; ··· 60 && !origin) { 61 warning(_("Not setting branch %s as its own upstream."), 62 local); 63 - return; 64 } 65 66 strbuf_addf(&key, "branch.%s.remote", local); 67 - git_config_set(key.buf, origin ? origin : "."); 68 69 strbuf_reset(&key); 70 strbuf_addf(&key, "branch.%s.merge", local); 71 - git_config_set(key.buf, remote); 72 73 if (rebasing) { 74 strbuf_reset(&key); 75 strbuf_addf(&key, "branch.%s.rebase", local); 76 - git_config_set(key.buf, "true"); 77 } 78 strbuf_release(&key); 79 ··· 102 local, remote); 103 } 104 } 105 } 106 107 /* ··· 109 * to infer the settings for branch.<new_ref>.{remote,merge} from the 110 * config. 111 */ 112 - static int setup_tracking(const char *new_ref, const char *orig_ref, 113 - enum branch_track track, int quiet) 114 { 115 struct tracking tracking; 116 int config_flags = quiet ? 0 : BRANCH_CONFIG_VERBOSE; ··· 118 memset(&tracking, 0, sizeof(tracking)); 119 tracking.spec.dst = (char *)orig_ref; 120 if (for_each_remote(find_tracked_branch, &tracking)) 121 - return 1; 122 123 if (!tracking.matches) 124 switch (track) { ··· 127 case BRANCH_TRACK_OVERRIDE: 128 break; 129 default: 130 - return 1; 131 } 132 133 if (tracking.matches > 1) 134 - return error(_("Not tracking: ambiguous information for ref %s"), 135 - orig_ref); 136 137 - install_branch_config(config_flags, new_ref, tracking.remote, 138 - tracking.src ? tracking.src : orig_ref); 139 140 free(tracking.src); 141 - return 0; 142 } 143 144 int read_branch_desc(struct strbuf *buf, const char *branch_name)
··· 49 return 0; 50 } 51 52 + static const char tracking_advice[] = 53 + N_("\n" 54 + "After fixing the error cause you may try to fix up\n" 55 + "the remote tracking information by invoking\n" 56 + "\"git branch --set-upstream-to=%s%s%s\"."); 57 + 58 + int install_branch_config(int flag, const char *local, const char *origin, const char *remote) 59 { 60 const char *shortname = NULL; 61 struct strbuf key = STRBUF_INIT; ··· 66 && !origin) { 67 warning(_("Not setting branch %s as its own upstream."), 68 local); 69 + return 0; 70 } 71 72 strbuf_addf(&key, "branch.%s.remote", local); 73 + if (git_config_set_gently(key.buf, origin ? origin : ".") < 0) 74 + goto out_err; 75 76 strbuf_reset(&key); 77 strbuf_addf(&key, "branch.%s.merge", local); 78 + if (git_config_set_gently(key.buf, remote) < 0) 79 + goto out_err; 80 81 if (rebasing) { 82 strbuf_reset(&key); 83 strbuf_addf(&key, "branch.%s.rebase", local); 84 + if (git_config_set_gently(key.buf, "true") < 0) 85 + goto out_err; 86 } 87 strbuf_release(&key); 88 ··· 111 local, remote); 112 } 113 } 114 + 115 + return 0; 116 + 117 + out_err: 118 + strbuf_release(&key); 119 + error(_("Unable to write upstream branch configuration")); 120 + 121 + advise(_(tracking_advice), 122 + origin ? origin : "", 123 + origin ? "/" : "", 124 + shortname ? shortname : remote); 125 + 126 + return -1; 127 } 128 129 /* ··· 131 * to infer the settings for branch.<new_ref>.{remote,merge} from the 132 * config. 133 */ 134 + static void setup_tracking(const char *new_ref, const char *orig_ref, 135 + enum branch_track track, int quiet) 136 { 137 struct tracking tracking; 138 int config_flags = quiet ? 0 : BRANCH_CONFIG_VERBOSE; ··· 140 memset(&tracking, 0, sizeof(tracking)); 141 tracking.spec.dst = (char *)orig_ref; 142 if (for_each_remote(find_tracked_branch, &tracking)) 143 + return; 144 145 if (!tracking.matches) 146 switch (track) { ··· 149 case BRANCH_TRACK_OVERRIDE: 150 break; 151 default: 152 + return; 153 } 154 155 if (tracking.matches > 1) 156 + die(_("Not tracking: ambiguous information for ref %s"), 157 + orig_ref); 158 159 + if (install_branch_config(config_flags, new_ref, tracking.remote, 160 + tracking.src ? tracking.src : orig_ref) < 0) 161 + exit(-1); 162 163 free(tracking.src); 164 } 165 166 int read_branch_desc(struct strbuf *buf, const char *branch_name)
+2 -1
branch.h
··· 43 /* 44 * Configure local branch "local" as downstream to branch "remote" 45 * from remote "origin". Used by git branch --set-upstream. 46 */ 47 #define BRANCH_CONFIG_VERBOSE 01 48 - extern void install_branch_config(int flag, const char *local, const char *origin, const char *remote); 49 50 /* 51 * Read branch description
··· 43 /* 44 * Configure local branch "local" as downstream to branch "remote" 45 * from remote "origin". Used by git branch --set-upstream. 46 + * Returns 0 on success. 47 */ 48 #define BRANCH_CONFIG_VERBOSE 01 49 + extern int install_branch_config(int flag, const char *local, const char *origin, const char *remote); 50 51 /* 52 * Read branch description
+2 -3
builtin/branch.c
··· 570 571 static int edit_branch_description(const char *branch_name) 572 { 573 - int status; 574 struct strbuf buf = STRBUF_INIT; 575 struct strbuf name = STRBUF_INIT; 576 ··· 595 strbuf_stripspace(&buf, 1); 596 597 strbuf_addf(&name, "branch.%s.description", branch_name); 598 - status = git_config_set(name.buf, buf.len ? buf.buf : NULL); 599 strbuf_release(&name); 600 strbuf_release(&buf); 601 602 - return status; 603 } 604 605 int cmd_branch(int argc, const char **argv, const char *prefix)
··· 570 571 static int edit_branch_description(const char *branch_name) 572 { 573 struct strbuf buf = STRBUF_INIT; 574 struct strbuf name = STRBUF_INIT; 575 ··· 594 strbuf_stripspace(&buf, 1); 595 596 strbuf_addf(&name, "branch.%s.description", branch_name); 597 + git_config_set(name.buf, buf.len ? buf.buf : NULL); 598 strbuf_release(&name); 599 strbuf_release(&buf); 600 601 + return 0; 602 } 603 604 int cmd_branch(int argc, const char **argv, const char *prefix)
+1 -1
builtin/clone.c
··· 740 741 static int write_one_config(const char *key, const char *value, void *data) 742 { 743 - return git_config_set_multivar(key, value ? value : "true", "^$", 0); 744 } 745 746 static void write_config(struct string_list *config)
··· 740 741 static int write_one_config(const char *key, const char *value, void *data) 742 { 743 + return git_config_set_multivar_gently(key, value ? value : "true", "^$", 0); 744 } 745 746 static void write_config(struct string_list *config)
+14 -14
builtin/config.c
··· 615 check_write(); 616 check_argc(argc, 2, 2); 617 value = normalize_value(argv[0], argv[1]); 618 - ret = git_config_set_in_file(given_config_source.file, argv[0], value); 619 if (ret == CONFIG_NOTHING_SET) 620 error("cannot overwrite multiple values with a single value\n" 621 " Use a regexp, --add or --replace-all to change %s.", argv[0]); ··· 625 check_write(); 626 check_argc(argc, 2, 3); 627 value = normalize_value(argv[0], argv[1]); 628 - return git_config_set_multivar_in_file(given_config_source.file, 629 - argv[0], value, argv[2], 0); 630 } 631 else if (actions == ACTION_ADD) { 632 check_write(); 633 check_argc(argc, 2, 2); 634 value = normalize_value(argv[0], argv[1]); 635 - return git_config_set_multivar_in_file(given_config_source.file, 636 - argv[0], value, 637 - CONFIG_REGEX_NONE, 0); 638 } 639 else if (actions == ACTION_REPLACE_ALL) { 640 check_write(); 641 check_argc(argc, 2, 3); 642 value = normalize_value(argv[0], argv[1]); 643 - return git_config_set_multivar_in_file(given_config_source.file, 644 - argv[0], value, argv[2], 1); 645 } 646 else if (actions == ACTION_GET) { 647 check_argc(argc, 1, 2); ··· 667 check_write(); 668 check_argc(argc, 1, 2); 669 if (argc == 2) 670 - return git_config_set_multivar_in_file(given_config_source.file, 671 - argv[0], NULL, argv[1], 0); 672 else 673 - return git_config_set_in_file(given_config_source.file, 674 - argv[0], NULL); 675 } 676 else if (actions == ACTION_UNSET_ALL) { 677 check_write(); 678 check_argc(argc, 1, 2); 679 - return git_config_set_multivar_in_file(given_config_source.file, 680 - argv[0], NULL, argv[1], 1); 681 } 682 else if (actions == ACTION_RENAME_SECTION) { 683 int ret;
··· 615 check_write(); 616 check_argc(argc, 2, 2); 617 value = normalize_value(argv[0], argv[1]); 618 + ret = git_config_set_in_file_gently(given_config_source.file, argv[0], value); 619 if (ret == CONFIG_NOTHING_SET) 620 error("cannot overwrite multiple values with a single value\n" 621 " Use a regexp, --add or --replace-all to change %s.", argv[0]); ··· 625 check_write(); 626 check_argc(argc, 2, 3); 627 value = normalize_value(argv[0], argv[1]); 628 + return git_config_set_multivar_in_file_gently(given_config_source.file, 629 + argv[0], value, argv[2], 0); 630 } 631 else if (actions == ACTION_ADD) { 632 check_write(); 633 check_argc(argc, 2, 2); 634 value = normalize_value(argv[0], argv[1]); 635 + return git_config_set_multivar_in_file_gently(given_config_source.file, 636 + argv[0], value, 637 + CONFIG_REGEX_NONE, 0); 638 } 639 else if (actions == ACTION_REPLACE_ALL) { 640 check_write(); 641 check_argc(argc, 2, 3); 642 value = normalize_value(argv[0], argv[1]); 643 + return git_config_set_multivar_in_file_gently(given_config_source.file, 644 + argv[0], value, argv[2], 1); 645 } 646 else if (actions == ACTION_GET) { 647 check_argc(argc, 1, 2); ··· 667 check_write(); 668 check_argc(argc, 1, 2); 669 if (argc == 2) 670 + return git_config_set_multivar_in_file_gently(given_config_source.file, 671 + argv[0], NULL, argv[1], 0); 672 else 673 + return git_config_set_in_file_gently(given_config_source.file, 674 + argv[0], NULL); 675 } 676 else if (actions == ACTION_UNSET_ALL) { 677 check_write(); 678 check_argc(argc, 1, 2); 679 + return git_config_set_multivar_in_file_gently(given_config_source.file, 680 + argv[0], NULL, argv[1], 1); 681 } 682 else if (actions == ACTION_RENAME_SECTION) { 683 int ret;
+1 -1
builtin/init-db.c
··· 250 git_config_set("core.bare", "false"); 251 /* allow template config file to override the default */ 252 if (log_all_ref_updates == -1) 253 - git_config_set("core.logallrefupdates", "true"); 254 if (needs_work_tree_config(get_git_dir(), work_tree)) 255 git_config_set("core.worktree", work_tree); 256 }
··· 250 git_config_set("core.bare", "false"); 251 /* allow template config file to override the default */ 252 if (log_all_ref_updates == -1) 253 + git_config_set("core.logallrefupdates", "true"); 254 if (needs_work_tree_config(get_git_dir(), work_tree)) 255 git_config_set("core.worktree", work_tree); 256 }
+24 -46
builtin/remote.c
··· 108 #define MIRROR_PUSH 2 109 #define MIRROR_BOTH (MIRROR_FETCH|MIRROR_PUSH) 110 111 - static int add_branch(const char *key, const char *branchname, 112 - const char *remotename, int mirror, struct strbuf *tmp) 113 { 114 strbuf_reset(tmp); 115 strbuf_addch(tmp, '+'); ··· 119 else 120 strbuf_addf(tmp, "refs/heads/%s:refs/remotes/%s/%s", 121 branchname, remotename, branchname); 122 - return git_config_set_multivar(key, tmp->buf, "^$", 0); 123 } 124 125 static const char mirror_advice[] = ··· 194 die(_("'%s' is not a valid remote name"), name); 195 196 strbuf_addf(&buf, "remote.%s.url", name); 197 - if (git_config_set(buf.buf, url)) 198 - return 1; 199 200 if (!mirror || mirror & MIRROR_FETCH) { 201 strbuf_reset(&buf); ··· 203 if (track.nr == 0) 204 string_list_append(&track, "*"); 205 for (i = 0; i < track.nr; i++) { 206 - if (add_branch(buf.buf, track.items[i].string, 207 - name, mirror, &buf2)) 208 - return 1; 209 } 210 } 211 212 if (mirror & MIRROR_PUSH) { 213 strbuf_reset(&buf); 214 strbuf_addf(&buf, "remote.%s.mirror", name); 215 - if (git_config_set(buf.buf, "true")) 216 - return 1; 217 } 218 219 if (fetch_tags != TAGS_DEFAULT) { 220 strbuf_reset(&buf); 221 strbuf_addf(&buf, "remote.%s.tagopt", name); 222 - if (git_config_set(buf.buf, 223 - fetch_tags == TAGS_SET ? "--tags" : "--no-tags")) 224 - return 1; 225 } 226 227 if (fetch && fetch_remote(name)) ··· 589 590 strbuf_addf(&buf, "remote.%s.url", remote->name); 591 for (i = 0; i < remote->url_nr; i++) 592 - if (git_config_set_multivar(buf.buf, remote->url[i], "^$", 0)) 593 - return error(_("Could not append '%s' to '%s'"), 594 - remote->url[i], buf.buf); 595 strbuf_reset(&buf); 596 strbuf_addf(&buf, "remote.%s.push", remote->name); 597 for (i = 0; i < remote->push_refspec_nr; i++) 598 - if (git_config_set_multivar(buf.buf, remote->push_refspec[i], "^$", 0)) 599 - return error(_("Could not append '%s' to '%s'"), 600 - remote->push_refspec[i], buf.buf); 601 strbuf_reset(&buf); 602 strbuf_addf(&buf, "remote.%s.fetch", remote->name); 603 for (i = 0; i < remote->fetch_refspec_nr; i++) 604 - if (git_config_set_multivar(buf.buf, remote->fetch_refspec[i], "^$", 0)) 605 - return error(_("Could not append '%s' to '%s'"), 606 - remote->fetch_refspec[i], buf.buf); 607 if (remote->origin == REMOTE_REMOTES) 608 unlink_or_warn(git_path("remotes/%s", remote->name)); 609 else if (remote->origin == REMOTE_BRANCHES) 610 unlink_or_warn(git_path("branches/%s", remote->name)); 611 return 0; 612 } 613 ··· 654 655 strbuf_reset(&buf); 656 strbuf_addf(&buf, "remote.%s.fetch", rename.new); 657 - if (git_config_set_multivar(buf.buf, NULL, NULL, 1)) 658 - return error(_("Could not remove config section '%s'"), buf.buf); 659 strbuf_addf(&old_remote_context, ":refs/remotes/%s/", rename.old); 660 for (i = 0; i < oldremote->fetch_refspec_nr; i++) { 661 char *ptr; ··· 675 "\tPlease update the configuration manually if necessary."), 676 buf2.buf); 677 678 - if (git_config_set_multivar(buf.buf, buf2.buf, "^$", 0)) 679 - return error(_("Could not append '%s'"), buf.buf); 680 } 681 682 read_branches(); ··· 686 if (info->remote_name && !strcmp(info->remote_name, rename.old)) { 687 strbuf_reset(&buf); 688 strbuf_addf(&buf, "branch.%s.remote", item->string); 689 - if (git_config_set(buf.buf, rename.new)) { 690 - return error(_("Could not set '%s'"), buf.buf); 691 - } 692 } 693 } 694 ··· 786 strbuf_reset(&buf); 787 strbuf_addf(&buf, "branch.%s.%s", 788 item->string, *k); 789 - if (git_config_set(buf.buf, NULL)) { 790 - strbuf_release(&buf); 791 - return -1; 792 - } 793 } 794 } 795 } ··· 1410 1411 static int remove_all_fetch_refspecs(const char *remote, const char *key) 1412 { 1413 - return git_config_set_multivar(key, NULL, NULL, 1); 1414 } 1415 1416 - static int add_branches(struct remote *remote, const char **branches, 1417 - const char *key) 1418 { 1419 const char *remotename = remote->name; 1420 int mirror = remote->mirror; 1421 struct strbuf refspec = STRBUF_INIT; 1422 1423 for (; *branches; branches++) 1424 - if (add_branch(key, *branches, remotename, mirror, &refspec)) { 1425 - strbuf_release(&refspec); 1426 - return 1; 1427 - } 1428 1429 strbuf_release(&refspec); 1430 - return 0; 1431 } 1432 1433 static int set_remote_branches(const char *remotename, const char **branches, ··· 1446 strbuf_release(&key); 1447 return 1; 1448 } 1449 - if (add_branches(remote, branches, key.buf)) { 1450 - strbuf_release(&key); 1451 - return 1; 1452 - } 1453 1454 strbuf_release(&key); 1455 return 0; ··· 1581 if ((!oldurl && !delete_mode) || add_mode) { 1582 if (add_mode) 1583 git_config_set_multivar(name_buf.buf, newurl, 1584 - "^$", 0); 1585 else 1586 git_config_set(name_buf.buf, newurl); 1587 strbuf_release(&name_buf); 1588 return 0; 1589 } 1590
··· 108 #define MIRROR_PUSH 2 109 #define MIRROR_BOTH (MIRROR_FETCH|MIRROR_PUSH) 110 111 + static void add_branch(const char *key, const char *branchname, 112 + const char *remotename, int mirror, struct strbuf *tmp) 113 { 114 strbuf_reset(tmp); 115 strbuf_addch(tmp, '+'); ··· 119 else 120 strbuf_addf(tmp, "refs/heads/%s:refs/remotes/%s/%s", 121 branchname, remotename, branchname); 122 + git_config_set_multivar(key, tmp->buf, "^$", 0); 123 } 124 125 static const char mirror_advice[] = ··· 194 die(_("'%s' is not a valid remote name"), name); 195 196 strbuf_addf(&buf, "remote.%s.url", name); 197 + git_config_set(buf.buf, url); 198 199 if (!mirror || mirror & MIRROR_FETCH) { 200 strbuf_reset(&buf); ··· 202 if (track.nr == 0) 203 string_list_append(&track, "*"); 204 for (i = 0; i < track.nr; i++) { 205 + add_branch(buf.buf, track.items[i].string, 206 + name, mirror, &buf2); 207 } 208 } 209 210 if (mirror & MIRROR_PUSH) { 211 strbuf_reset(&buf); 212 strbuf_addf(&buf, "remote.%s.mirror", name); 213 + git_config_set(buf.buf, "true"); 214 } 215 216 if (fetch_tags != TAGS_DEFAULT) { 217 strbuf_reset(&buf); 218 strbuf_addf(&buf, "remote.%s.tagopt", name); 219 + git_config_set(buf.buf, 220 + fetch_tags == TAGS_SET ? "--tags" : "--no-tags"); 221 } 222 223 if (fetch && fetch_remote(name)) ··· 585 586 strbuf_addf(&buf, "remote.%s.url", remote->name); 587 for (i = 0; i < remote->url_nr; i++) 588 + git_config_set_multivar(buf.buf, remote->url[i], "^$", 0); 589 strbuf_reset(&buf); 590 strbuf_addf(&buf, "remote.%s.push", remote->name); 591 for (i = 0; i < remote->push_refspec_nr; i++) 592 + git_config_set_multivar(buf.buf, remote->push_refspec[i], "^$", 0); 593 strbuf_reset(&buf); 594 strbuf_addf(&buf, "remote.%s.fetch", remote->name); 595 for (i = 0; i < remote->fetch_refspec_nr; i++) 596 + git_config_set_multivar(buf.buf, remote->fetch_refspec[i], "^$", 0); 597 if (remote->origin == REMOTE_REMOTES) 598 unlink_or_warn(git_path("remotes/%s", remote->name)); 599 else if (remote->origin == REMOTE_BRANCHES) 600 unlink_or_warn(git_path("branches/%s", remote->name)); 601 + 602 return 0; 603 } 604 ··· 645 646 strbuf_reset(&buf); 647 strbuf_addf(&buf, "remote.%s.fetch", rename.new); 648 + git_config_set_multivar(buf.buf, NULL, NULL, 1); 649 strbuf_addf(&old_remote_context, ":refs/remotes/%s/", rename.old); 650 for (i = 0; i < oldremote->fetch_refspec_nr; i++) { 651 char *ptr; ··· 665 "\tPlease update the configuration manually if necessary."), 666 buf2.buf); 667 668 + git_config_set_multivar(buf.buf, buf2.buf, "^$", 0); 669 } 670 671 read_branches(); ··· 675 if (info->remote_name && !strcmp(info->remote_name, rename.old)) { 676 strbuf_reset(&buf); 677 strbuf_addf(&buf, "branch.%s.remote", item->string); 678 + git_config_set(buf.buf, rename.new); 679 } 680 } 681 ··· 773 strbuf_reset(&buf); 774 strbuf_addf(&buf, "branch.%s.%s", 775 item->string, *k); 776 + git_config_set(buf.buf, NULL); 777 } 778 } 779 } ··· 1394 1395 static int remove_all_fetch_refspecs(const char *remote, const char *key) 1396 { 1397 + return git_config_set_multivar_gently(key, NULL, NULL, 1); 1398 } 1399 1400 + static void add_branches(struct remote *remote, const char **branches, 1401 + const char *key) 1402 { 1403 const char *remotename = remote->name; 1404 int mirror = remote->mirror; 1405 struct strbuf refspec = STRBUF_INIT; 1406 1407 for (; *branches; branches++) 1408 + add_branch(key, *branches, remotename, mirror, &refspec); 1409 1410 strbuf_release(&refspec); 1411 } 1412 1413 static int set_remote_branches(const char *remotename, const char **branches, ··· 1426 strbuf_release(&key); 1427 return 1; 1428 } 1429 + add_branches(remote, branches, key.buf); 1430 1431 strbuf_release(&key); 1432 return 0; ··· 1558 if ((!oldurl && !delete_mode) || add_mode) { 1559 if (add_mode) 1560 git_config_set_multivar(name_buf.buf, newurl, 1561 + "^$", 0); 1562 else 1563 git_config_set(name_buf.buf, newurl); 1564 strbuf_release(&name_buf); 1565 + 1566 return 0; 1567 } 1568
+9 -5
cache.h
··· 1489 /* git_config_parse_key() returns these negated: */ 1490 #define CONFIG_INVALID_KEY 1 1491 #define CONFIG_NO_SECTION_OR_NAME 2 1492 - /* git_config_set(), git_config_set_multivar() return the above or these: */ 1493 #define CONFIG_NO_LOCK -1 1494 #define CONFIG_INVALID_FILE 3 1495 #define CONFIG_NO_WRITE 4 ··· 1527 extern int git_config_maybe_bool(const char *, const char *); 1528 extern int git_config_string(const char **, const char *, const char *); 1529 extern int git_config_pathname(const char **, const char *, const char *); 1530 - extern int git_config_set_in_file(const char *, const char *, const char *); 1531 - extern int git_config_set(const char *, const char *); 1532 extern int git_config_parse_key(const char *, char **, int *); 1533 extern int git_config_key_is_valid(const char *key); 1534 - extern int git_config_set_multivar(const char *, const char *, const char *, int); 1535 - extern int git_config_set_multivar_in_file(const char *, const char *, const char *, const char *, int); 1536 extern int git_config_rename_section(const char *, const char *); 1537 extern int git_config_rename_section_in_file(const char *, const char *, const char *); 1538 extern const char *git_etc_gitconfig(void);
··· 1489 /* git_config_parse_key() returns these negated: */ 1490 #define CONFIG_INVALID_KEY 1 1491 #define CONFIG_NO_SECTION_OR_NAME 2 1492 + /* git_config_set_gently(), git_config_set_multivar_gently() return the above or these: */ 1493 #define CONFIG_NO_LOCK -1 1494 #define CONFIG_INVALID_FILE 3 1495 #define CONFIG_NO_WRITE 4 ··· 1527 extern int git_config_maybe_bool(const char *, const char *); 1528 extern int git_config_string(const char **, const char *, const char *); 1529 extern int git_config_pathname(const char **, const char *, const char *); 1530 + extern int git_config_set_in_file_gently(const char *, const char *, const char *); 1531 + extern void git_config_set_in_file(const char *, const char *, const char *); 1532 + extern int git_config_set_gently(const char *, const char *); 1533 + extern void git_config_set(const char *, const char *); 1534 extern int git_config_parse_key(const char *, char **, int *); 1535 extern int git_config_key_is_valid(const char *key); 1536 + extern int git_config_set_multivar_gently(const char *, const char *, const char *, int); 1537 + extern void git_config_set_multivar(const char *, const char *, const char *, int); 1538 + extern int git_config_set_multivar_in_file_gently(const char *, const char *, const char *, const char *, int); 1539 + extern void git_config_set_multivar_in_file(const char *, const char *, const char *, const char *, int); 1540 extern int git_config_rename_section(const char *, const char *); 1541 extern int git_config_rename_section_in_file(const char *, const char *, const char *); 1542 extern const char *git_etc_gitconfig(void);
+2 -1
compat/precompose_utf8.c
··· 50 close(output_fd); 51 git_path_buf(&path, "%s", auml_nfd); 52 precomposed_unicode = access(path.buf, R_OK) ? 0 : 1; 53 - git_config_set("core.precomposeunicode", precomposed_unicode ? "true" : "false"); 54 git_path_buf(&path, "%s", auml_nfc); 55 if (unlink(path.buf)) 56 die_errno(_("failed to unlink '%s'"), path.buf);
··· 50 close(output_fd); 51 git_path_buf(&path, "%s", auml_nfd); 52 precomposed_unicode = access(path.buf, R_OK) ? 0 : 1; 53 + git_config_set("core.precomposeunicode", 54 + precomposed_unicode ? "true" : "false"); 55 git_path_buf(&path, "%s", auml_nfc); 56 if (unlink(path.buf)) 57 die_errno(_("failed to unlink '%s'"), path.buf);
+40 -12
config.c
··· 1853 return offset; 1854 } 1855 1856 - int git_config_set_in_file(const char *config_filename, 1857 - const char *key, const char *value) 1858 { 1859 - return git_config_set_multivar_in_file(config_filename, key, value, NULL, 0); 1860 } 1861 1862 - int git_config_set(const char *key, const char *value) 1863 { 1864 - return git_config_set_multivar(key, value, NULL, 0); 1865 } 1866 1867 /* ··· 1976 * - the config file is removed and the lock file rename()d to it. 1977 * 1978 */ 1979 - int git_config_set_multivar_in_file(const char *config_filename, 1980 - const char *key, const char *value, 1981 - const char *value_regex, int multi_replace) 1982 { 1983 int fd = -1, in_fd = -1; 1984 int ret; ··· 2205 2206 } 2207 2208 - int git_config_set_multivar(const char *key, const char *value, 2209 - const char *value_regex, int multi_replace) 2210 { 2211 - return git_config_set_multivar_in_file(NULL, key, value, value_regex, 2212 - multi_replace); 2213 } 2214 2215 static int section_name_match (const char *buf, const char *name)
··· 1853 return offset; 1854 } 1855 1856 + int git_config_set_in_file_gently(const char *config_filename, 1857 + const char *key, const char *value) 1858 + { 1859 + return git_config_set_multivar_in_file_gently(config_filename, key, value, NULL, 0); 1860 + } 1861 + 1862 + void git_config_set_in_file(const char *config_filename, 1863 + const char *key, const char *value) 1864 + { 1865 + git_config_set_multivar_in_file(config_filename, key, value, NULL, 0); 1866 + } 1867 + 1868 + int git_config_set_gently(const char *key, const char *value) 1869 { 1870 + return git_config_set_multivar_gently(key, value, NULL, 0); 1871 } 1872 1873 + void git_config_set(const char *key, const char *value) 1874 { 1875 + git_config_set_multivar(key, value, NULL, 0); 1876 } 1877 1878 /* ··· 1987 * - the config file is removed and the lock file rename()d to it. 1988 * 1989 */ 1990 + int git_config_set_multivar_in_file_gently(const char *config_filename, 1991 + const char *key, const char *value, 1992 + const char *value_regex, 1993 + int multi_replace) 1994 { 1995 int fd = -1, in_fd = -1; 1996 int ret; ··· 2217 2218 } 2219 2220 + void git_config_set_multivar_in_file(const char *config_filename, 2221 + const char *key, const char *value, 2222 + const char *value_regex, int multi_replace) 2223 { 2224 + if (git_config_set_multivar_in_file_gently(config_filename, key, value, 2225 + value_regex, multi_replace) < 0) 2226 + die(_("Could not set '%s' to '%s'"), key, value); 2227 + } 2228 + 2229 + int git_config_set_multivar_gently(const char *key, const char *value, 2230 + const char *value_regex, int multi_replace) 2231 + { 2232 + return git_config_set_multivar_in_file_gently(NULL, key, value, value_regex, 2233 + multi_replace); 2234 + } 2235 + 2236 + void git_config_set_multivar(const char *key, const char *value, 2237 + const char *value_regex, int multi_replace) 2238 + { 2239 + git_config_set_multivar_in_file(NULL, key, value, value_regex, 2240 + multi_replace); 2241 } 2242 2243 static int section_name_match (const char *buf, const char *name)
+4 -6
submodule.c
··· 69 strbuf_addstr(&entry, "submodule."); 70 strbuf_addstr(&entry, submodule->name); 71 strbuf_addstr(&entry, ".path"); 72 - if (git_config_set_in_file(".gitmodules", entry.buf, newpath) < 0) { 73 /* Maybe the user already did that, don't error out here */ 74 warning(_("Could not update .gitmodules entry %s"), entry.buf); 75 strbuf_release(&entry); ··· 1087 /* Update core.worktree setting */ 1088 strbuf_reset(&file_name); 1089 strbuf_addf(&file_name, "%s/config", git_dir); 1090 - if (git_config_set_in_file(file_name.buf, "core.worktree", 1091 - relative_path(real_work_tree, git_dir, 1092 - &rel_path))) 1093 - die(_("Could not set core.worktree in %s"), 1094 - file_name.buf); 1095 1096 strbuf_release(&file_name); 1097 strbuf_release(&rel_path);
··· 69 strbuf_addstr(&entry, "submodule."); 70 strbuf_addstr(&entry, submodule->name); 71 strbuf_addstr(&entry, ".path"); 72 + if (git_config_set_in_file_gently(".gitmodules", entry.buf, newpath) < 0) { 73 /* Maybe the user already did that, don't error out here */ 74 warning(_("Could not update .gitmodules entry %s"), entry.buf); 75 strbuf_release(&entry); ··· 1087 /* Update core.worktree setting */ 1088 strbuf_reset(&file_name); 1089 strbuf_addf(&file_name, "%s/config", git_dir); 1090 + git_config_set_in_file(file_name.buf, "core.worktree", 1091 + relative_path(real_work_tree, git_dir, 1092 + &rel_path)); 1093 1094 strbuf_release(&file_name); 1095 strbuf_release(&rel_path);
+15 -1
t/t3200-branch.sh
··· 446 test_must_fail git branch --set-upstream-to HEAD^{} 447 ' 448 449 test_expect_success 'use --set-upstream-to modify HEAD' ' 450 test_config branch.master.remote foo && 451 test_config branch.master.merge foo && ··· 464 465 test_expect_success '--unset-upstream should fail if given a non-existent branch' ' 466 test_must_fail git branch --unset-upstream i-dont-exist 467 ' 468 469 test_expect_success 'test --unset-upstream on HEAD' ' ··· 579 git config remote.ambi1.fetch refs/heads/lalala:refs/heads/master && 580 git config remote.ambi2.url lilili && 581 git config remote.ambi2.fetch refs/heads/lilili:refs/heads/master && 582 - git branch all1 master && 583 test -z "$(git config branch.all1.merge)" 584 ' 585
··· 446 test_must_fail git branch --set-upstream-to HEAD^{} 447 ' 448 449 + test_expect_success '--set-upstream-to fails on locked config' ' 450 + test_when_finished "rm -f .git/config.lock" && 451 + >.git/config.lock && 452 + git branch locked && 453 + test_must_fail git branch --set-upstream-to locked 454 + ' 455 + 456 test_expect_success 'use --set-upstream-to modify HEAD' ' 457 test_config branch.master.remote foo && 458 test_config branch.master.merge foo && ··· 471 472 test_expect_success '--unset-upstream should fail if given a non-existent branch' ' 473 test_must_fail git branch --unset-upstream i-dont-exist 474 + ' 475 + 476 + test_expect_success '--unset-upstream should fail if config is locked' ' 477 + test_when_finished "rm -f .git/config.lock" && 478 + git branch --set-upstream-to locked && 479 + >.git/config.lock && 480 + test_must_fail git branch --unset-upstream 481 ' 482 483 test_expect_success 'test --unset-upstream on HEAD' ' ··· 593 git config remote.ambi1.fetch refs/heads/lalala:refs/heads/master && 594 git config remote.ambi2.url lilili && 595 git config remote.ambi2.fetch refs/heads/lilili:refs/heads/master && 596 + test_must_fail git branch all1 master && 597 test -z "$(git config branch.all1.merge)" 598 ' 599
+9
t/t5505-remote.sh
··· 970 echo foo | get_url_test --push --all someremote 971 ' 972 973 test_expect_success 'remote set-url bar' ' 974 git remote set-url someremote bar && 975 echo bar >expect &&
··· 970 echo foo | get_url_test --push --all someremote 971 ' 972 973 + test_expect_success 'remote set-url with locked config' ' 974 + test_when_finished "rm -f .git/config.lock" && 975 + git config --get-all remote.someremote.url >expect && 976 + >.git/config.lock && 977 + test_must_fail git remote set-url someremote baz && 978 + git config --get-all remote.someremote.url >actual && 979 + cmp expect actual 980 + ' 981 + 982 test_expect_success 'remote set-url bar' ' 983 git remote set-url someremote bar && 984 echo bar >expect &&