X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=builtin-branch.c;h=7408285050a0f41a33d31c73e79c2fdefe567593;hb=a6e3768f641c2703266422aa05c05f1d01e886b2;hp=42b1ff129e7d5bbea47a4d1af955395014f200f9;hpb=36db2399e023c1526fac0b142524229554b88419;p=git.git diff --git a/builtin-branch.c b/builtin-branch.c index 42b1ff129..740828505 100644 --- a/builtin-branch.c +++ b/builtin-branch.c @@ -372,9 +372,26 @@ static int get_remote_config(const char *key, const char *value) return 0; } -static void set_branch_defaults(const char *name, const char *real_ref) +static void set_branch_merge(const char *name, const char *config_remote, + const char *config_repo) { char key[1024]; + if (sizeof(key) <= + snprintf(key, sizeof(key), "branch.%s.remote", name)) + die("what a long branch name you have!"); + git_config_set(key, config_remote); + + /* + * We do not have to check if we have enough space for + * the 'merge' key, since it's shorter than the + * previous 'remote' key, which we already checked. + */ + snprintf(key, sizeof(key), "branch.%s.merge", name); + git_config_set(key, config_repo); +} + +static void set_branch_defaults(const char *name, const char *real_ref) +{ const char *slash = strrchr(real_ref, '/'); if (!slash) @@ -384,21 +401,15 @@ static void set_branch_defaults(const char *name, const char *real_ref) start_len = strlen(real_ref); base_len = slash - real_ref; git_config(get_remote_config); + if (!config_repo && !config_remote && + !prefixcmp(real_ref, "refs/heads/")) { + set_branch_merge(name, ".", real_ref); + printf("Branch %s set up to track local branch %s.\n", + name, real_ref); + } if (config_repo && config_remote) { - if (sizeof(key) <= - snprintf(key, sizeof(key), "branch.%s.remote", name)) - die("what a long branch name you have!"); - git_config_set(key, config_remote); - - /* - * We do not have to check if we have enough space for - * the 'merge' key, since it's shorter than the - * previous 'remote' key, which we already checked. - */ - snprintf(key, sizeof(key), "branch.%s.merge", name); - git_config_set(key, config_repo); - + set_branch_merge(name, config_remote, config_repo); printf("Branch %s set up to track remote branch %s.\n", name, real_ref); } @@ -482,6 +493,7 @@ static void rename_branch(const char *oldname, const char *newname, int force) { char oldref[PATH_MAX], newref[PATH_MAX], logmsg[PATH_MAX*2 + 100]; unsigned char sha1[20]; + char oldsection[PATH_MAX], newsection[PATH_MAX]; if (!oldname) die("cannot rename the current branch while not on any."); @@ -510,6 +522,11 @@ static void rename_branch(const char *oldname, const char *newname, int force) /* no need to pass logmsg here as HEAD didn't really move */ if (!strcmp(oldname, head) && create_symref("HEAD", newref, NULL)) die("Branch renamed to %s, but HEAD is not updated!", newname); + + snprintf(oldsection, sizeof(oldsection), "branch.%s", oldref + 11); + snprintf(newsection, sizeof(newsection), "branch.%s", newref + 11); + if (git_config_rename_section(oldsection, newsection) < 0) + die("Branch is renamed, but update of config-file failed"); } int cmd_branch(int argc, const char **argv, const char *prefix)