summaryrefslogtreecommitdiff
path: root/branch.c
diff options
context:
space:
mode:
authorKazuki Yamaguchi <k@rhe.jp>2016-03-27 14:37:14 (GMT)
committerJunio C Hamano <gitster@pobox.com>2016-04-04 19:57:22 (GMT)
commit70999e9ceca47e03b8900bfb310b2f804125811e (patch)
tree8a1b8017985cb7def44f282dfde91844102c8e45 /branch.c
parent2233066e778e32dfab0471ea2ad8d1c7a94b7e39 (diff)
downloadgit-70999e9ceca47e03b8900bfb310b2f804125811e.zip
git-70999e9ceca47e03b8900bfb310b2f804125811e.tar.gz
git-70999e9ceca47e03b8900bfb310b2f804125811e.tar.bz2
branch -m: update all per-worktree HEADs
When renaming a branch, currently only the HEAD of current working tree is updated, but it must update HEADs of all working trees which point at the old branch. This is the current behavior, /path/to/wt's HEAD is not updated: % git worktree list /path/to 2c3c5f2 [master] /path/to/wt 2c3c5f2 [oldname] % git branch -m master master2 % git worktree list /path/to 2c3c5f2 [master2] /path/to/wt 2c3c5f2 [oldname] % git branch -m oldname newname % git worktree list /path/to 2c3c5f2 [master2] /path/to/wt 0000000 [oldname] This patch fixes this issue by updating all relevant worktree HEADs when renaming a branch. Signed-off-by: Kazuki Yamaguchi <k@rhe.jp> Signed-off-by: Junio C Hamano <gitster@pobox.com>
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 c50ea42..4162443 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;
+}