1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-11-01 23:07:55 +01:00
git/builtin
Eric Sunshine aaad2c948f checkout: improve die_if_checked_out() robustness
die_if_checked_out() is intended to check if the branch about to be
checked out is already checked out either in the main worktree or in a
linked worktree. However, if .git/worktrees directory does not exist,
then it never bothers checking the main worktree, even though the
specified branch might indeed be checked out there, which is fragile
behavior.

This hasn't been a problem in practice since the current implementation
of "git worktree add" (and, earlier, "git checkout --to") always creates
.git/worktrees before die_if_checked_out() is called by the child "git
checkout" invocation which populates the new worktree.

However, git-worktree will eventually want to call die_if_checked_out()
itself rather than only doing so indirectly as a side-effect of invoking
git-checkout, and reliance upon order of operations (creating
.git/worktrees before checking if a branch is already checked out) is
fragile. As a general function, callers should not be expected to abide
by this undocumented and unwarranted restriction. Therefore, make
die_if_checked_out() more robust by checking the main worktree whether
.git/worktrees exists or not.

While here, also move a comment explaining why die_if_checked_out()'s
helper parses HEAD manually. Such information resides more naturally
with the helper itself rather than at its first point of call.

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-07-20 11:29:24 -07:00
..
add.c lockfile.h: extract new header file for the functions in lockfile.c 2014-10-01 13:56:14 -07:00
annotate.c annotate: use argv_array 2014-07-16 11:10:11 -07:00
apply.c Merge branch 'rs/more-uses-of-skip-prefix' 2014-10-14 10:50:07 -07:00
archive.c
bisect--helper.c
blame.c refs.c: change resolve_ref_unsafe reading argument to be a flags field 2014-10-15 10:47:24 -07:00
branch.c use new wrapper write_file() for simple file writing 2014-12-01 11:00:16 -08:00
bundle.c
cat-file.c use skip_prefix() to avoid more magic numbers 2014-10-07 11:09:16 -07:00
check-attr.c
check-ignore.c
check-mailmap.c
check-ref-format.c
checkout-index.c lockfile.h: extract new header file for the functions in lockfile.c 2014-10-01 13:56:14 -07:00
checkout.c checkout: improve die_if_checked_out() robustness 2015-07-20 11:29:24 -07:00
clean.c Merge branch 'jn/parse-config-slot' 2014-10-20 12:23:48 -07:00
clone.c path.c: make get_pathname() call sites return const char * 2014-12-01 11:00:10 -08:00
column.c
commit-tree.c
commit.c commit: use SEQ_DIR instead of hardcoding "sequencer" 2014-12-01 11:00:12 -08:00
config.c Merge branch 'jn/parse-config-slot' 2014-10-20 12:23:48 -07:00
count-objects.c count-objects: report unused files in $GIT_DIR/worktrees/... 2014-12-01 11:00:18 -08:00
credential.c
describe.c lockfile.h: extract new header file for the functions in lockfile.c 2014-10-01 13:56:14 -07:00
diff-files.c
diff-index.c
diff-tree.c diff-tree: avoid lookup_unknown_object 2014-07-28 10:14:34 -07:00
diff.c lockfile.h: extract new header file for the functions in lockfile.c 2014-10-01 13:56:14 -07:00
fast-export.c teach fast-export an --anonymize option 2014-08-27 10:42:16 -07:00
fetch-pack.c
fetch.c path.c: make get_pathname() call sites return const char * 2014-12-01 11:00:10 -08:00
fmt-merge-msg.c refs.c: change resolve_ref_unsafe reading argument to be a flags field 2014-10-15 10:47:24 -07:00
for-each-ref.c Merge branch 'rs/ref-transaction' 2014-10-21 13:28:10 -07:00
fsck.c path.c: make get_pathname() call sites return const char * 2014-12-01 11:00:10 -08:00
gc.c config: rename "gc.pruneWorktreesExpire" to "gc.worktreePruneExpire" 2015-07-20 11:09:06 -07:00
get-tar-commit-id.c use skip_prefix() to avoid more magic numbers 2014-10-07 11:09:16 -07:00
grep.c make add_object_array_with_context interface more sane 2014-10-16 10:10:44 -07:00
hash-object.c hash-object: add --literally option 2014-09-11 14:23:51 -07:00
help.c doc: add 'everyday' to 'git help' 2014-10-10 16:02:26 -07:00
index-pack.c index-pack: fix compilation with NO_PTHREADS 2014-10-13 12:33:30 -07:00
init-db.c use new wrapper write_file() for simple file writing 2014-12-01 11:00:16 -08:00
interpret-trailers.c trailer: add interpret-trailers command 2014-10-13 13:55:27 -07:00
log.c Merge branch 'rs/ref-transaction' 2014-10-21 13:28:10 -07:00
ls-files.c grammofix in user-facing messages 2014-09-02 12:00:30 -07:00
ls-remote.c
ls-tree.c
mailinfo.c mailinfo: work around -Wstring-plus-int warning 2014-09-22 13:46:43 -07:00
mailsplit.c mailsplit: remove unnecessary unlink(2) call 2014-10-07 10:49:57 -07:00
merge-base.c
merge-file.c
merge-index.c
merge-ours.c
merge-recursive.c
merge-tree.c merge-tree: remove unused df_conflict arguments 2014-09-02 11:02:58 -07:00
merge.c refs.c: change resolve_ref_unsafe reading argument to be a flags field 2014-10-15 10:47:24 -07:00
mktag.c
mktree.c
mv.c lockfile.h: extract new header file for the functions in lockfile.c 2014-10-01 13:56:14 -07:00
name-rev.c
notes.c refs.c: change resolve_ref_unsafe reading argument to be a flags field 2014-10-15 10:47:24 -07:00
pack-objects.c Merge branch 'jk/prune-mtime' 2014-10-29 10:07:56 -07:00
pack-redundant.c
pack-refs.c
patch-id.c
prune-packed.c prune-packed: use for_each_loose_file_in_objdir 2014-10-16 10:10:40 -07:00
prune.c worktree: new place for "git prune --worktrees" 2015-06-29 08:48:44 -07:00
push.c push: heed user.signingkey for signed pushes 2014-10-24 10:50:05 -07:00
read-tree.c lockfile.h: extract new header file for the functions in lockfile.c 2014-10-01 13:56:14 -07:00
receive-pack.c path.c: make get_pathname() call sites return const char * 2014-12-01 11:00:10 -08:00
reflog.c reflog: avoid constructing .lock path with git_path 2014-12-01 11:00:12 -08:00
remote-ext.c use skip_prefix() to avoid more magic numbers 2014-10-07 11:09:16 -07:00
remote-fd.c
remote.c path.c: make get_pathname() call sites return const char * 2014-12-01 11:00:10 -08:00
repack.c path.c: make get_pathname() call sites return const char * 2014-12-01 11:00:10 -08:00
replace.c refs.c: pass the ref log message to _create/delete/update instead of _commit 2014-10-15 10:47:22 -07:00
rerere.c
reset.c lockfile.h: extract new header file for the functions in lockfile.c 2014-10-01 13:56:14 -07:00
rev-list.c
rev-parse.c setup.c: support multi-checkout repo setup 2014-12-01 11:00:15 -08:00
revert.c
rm.c lockfile.h: extract new header file for the functions in lockfile.c 2014-10-01 13:56:14 -07:00
send-pack.c Merge branch 'jc/push-cert' 2014-10-08 13:05:25 -07:00
shortlog.c
show-branch.c refs.c: change resolve_ref_unsafe reading argument to be a flags field 2014-10-15 10:47:24 -07:00
show-ref.c
stripspace.c
symbolic-ref.c refs.c: change resolve_ref_unsafe reading argument to be a flags field 2014-10-15 10:47:24 -07:00
tag.c refs.c: pass the ref log message to _create/delete/update instead of _commit 2014-10-15 10:47:22 -07:00
unpack-file.c
unpack-objects.c fsck_object(): allow passing object data separately from the object itself 2014-09-10 13:54:21 -07:00
update-index.c lockfile.h: extract new header file for the functions in lockfile.c 2014-10-01 13:56:14 -07:00
update-ref.c refs.c: pass the ref log message to _create/delete/update instead of _commit 2014-10-15 10:47:22 -07:00
update-server-info.c
upload-archive.c
var.c
verify-commit.c
verify-pack.c run-command: introduce CHILD_PROCESS_INIT 2014-08-20 09:53:37 -07:00
verify-tag.c
worktree.c Revert "checkout: retire --ignore-other-worktrees in favor of --force" 2015-07-12 09:38:21 -07:00
write-tree.c