aboutsummaryrefslogtreecommitdiff
path: root/branch.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2016-04-18 10:48:11 -0700
committerJunio C Hamano <gitster@pobox.com>2016-04-18 10:48:11 -0700
commit741a6942eb241dfc1317b7692381fc41dbb92501 (patch)
treed716da40ac03d8fbe811aeebacd9168d247ba186 /branch.c
parentb8b4d93100651876299eabaf76248510e616fab3 (diff)
parent18eb3a9ce7c544e74d424b942c5a5c9720c20112 (diff)
downloadgit-741a6942eb241dfc1317b7692381fc41dbb92501.tar.gz
git-741a6942eb241dfc1317b7692381fc41dbb92501.tar.xz
Merge branch 'ky/branch-m-worktree'
When "git worktree" feature is in use, "git branch -m" renamed a branch that is checked out in another worktree without adjusting the HEAD symbolic ref for the worktree. * ky/branch-m-worktree: set_worktree_head_symref(): fix error message branch -m: update all per-worktree HEADs refs: add a new function set_worktree_head_symref
Diffstat (limited to 'branch.c')
-rw-r--r--branch.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/branch.c b/branch.c
index c50ea4217..416244370 100644
--- a/branch.c
+++ b/branch.c
@@ -344,3 +344,26 @@ void die_if_checked_out(const char *branch)
die(_("'%s' is already checked out at '%s'"), branch, existing);
}
}
+
+int replace_each_worktree_head_symref(const char *oldref, const char *newref)
+{
+ int ret = 0;
+ struct worktree **worktrees = get_worktrees();
+ int i;
+
+ for (i = 0; worktrees[i]; i++) {
+ if (worktrees[i]->is_detached)
+ continue;
+ if (strcmp(oldref, worktrees[i]->head_ref))
+ continue;
+
+ if (set_worktree_head_symref(worktrees[i]->git_dir, newref)) {
+ ret = -1;
+ error(_("HEAD of working tree %s is not updated"),
+ worktrees[i]->path);
+ }
+ }
+
+ free_worktrees(worktrees);
+ return ret;
+}