summaryrefslogtreecommitdiff
path: root/builtin-checkout.c
AgeCommit message (Collapse)AuthorFilesLines
2009-09-07Merge branch 'tr/reset-checkout-patch'Libravatar Junio C Hamano1-0/+19
* tr/reset-checkout-patch: stash: simplify defaulting to "save" and reject unknown options Make test case number unique tests: disable interactive hunk selection tests if perl is not available DWIM 'git stash save -p' for 'git stash -p' Implement 'git stash save --patch' Implement 'git checkout --patch' Implement 'git reset --patch' builtin-add: refactor the meat of interactive_add() Add a small patch-mode testing library git-apply--interactive: Refactor patch mode code Make 'git stash -k' a short form for 'git stash save --keep-index'
2009-08-29UI consistency: allow --force for where -f means forceLibravatar René Scharfe1-1/+1
git branch, checkout, clean, mv and tag all have an option -f to override certain checks. This patch makes them accept the long option --force as a synonym. While we're at it, document that checkout support --quiet as synonym for its short option -q. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-08-28Merge branch 'jk/maint-1.6.3-checkout-unborn'Libravatar Junio C Hamano1-9/+3
* jk/maint-1.6.3-checkout-unborn: checkout: do not imply "-f" on unborn branches
2009-08-25checkout: do not imply "-f" on unborn branchesLibravatar Jeff King1-9/+3
When checkout sees that HEAD points to a non-existent ref, it currently acts as if "-f" was given; this behavior dates back to 5a03e7f, which enabled checkout from unborn branches in the shell version of "git-checkout". The reasoning given is to avoid the code path which tries to merge the tree contents. When checkout was converted to C, this code remained intact. The unfortunate side effect of this strategy is that the "force" code path will overwrite working tree and index state that may be precious to the user. Instead of enabling "force", this patch uses the normal "merge" codepath for an unborn branch, but substitutes the empty tree for the "old" commit. This means that in the absence of an index, any files in the working tree will be treated as untracked files, and a checkout which would overwrite them is aborted. Similarly, any paths in the index will be merged with an empty entry as the base, meaning that unless the new branch's content is identical to what's in the index, there will be a conflict and the checkout will be aborted. The user is then free to correct the situation or proceed with "-f" as appropriate. This patch also removes the "warning: you are on a branch yet to be born" message. Its function was to warn the user that we were enabling the "-f" option. Since we are no longer doing that, there is no reason for the user to care whether we are switching away from an unborn branch. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-08-15Implement 'git checkout --patch'Libravatar Thomas Rast1-0/+19
This introduces a --patch mode for git-checkout. In the index usage git checkout --patch -- [files...] it lets the user discard edits from the <files> at the granularity of hunks (by selecting hunks from 'git diff' and then reverse applying them to the worktree). We also accept a revision argument. In the case git checkout --patch HEAD -- [files...] we offer hunks from the difference between HEAD and the worktree, and reverse applies them to both index and worktree, allowing you to discard staged changes completely. In the non-HEAD usage git checkout --patch <revision> -- [files...] it offers hunks from the difference between the worktree and <revision>. The chosen hunks are then applied to both index and worktree. The application to worktree and index is done "atomically" in the sense that we first check if the patch applies to the index (it should always apply to the worktree). If it does not, we give the user a choice to either abort or apply to the worktree anyway. Signed-off-by: Thomas Rast <trast@student.ethz.ch> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-05-25Merge branch 'lt/maint-diff-reduce-lstat' into maintLibravatar Junio C Hamano1-2/+2
* lt/maint-diff-reduce-lstat: Teach 'git checkout' to preload the index contents Avoid unnecessary 'lstat()' calls in 'get_stat_data()'
2009-05-25parse-opts: prepare for OPT_FILENAMELibravatar Stephen Boyd1-1/+1
To give OPT_FILENAME the prefix, we pass the prefix to parse_options() which passes the prefix to parse_options_start() which sets the prefix member of parse_opts_ctx accordingly. If there isn't a prefix in the calling context, passing NULL will suffice. Signed-off-by: Stephen Boyd <bebarino@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-05-23Merge branch 'lt/maint-diff-reduce-lstat'Libravatar Junio C Hamano1-2/+2
* lt/maint-diff-reduce-lstat: Teach 'git checkout' to preload the index contents Avoid unnecessary 'lstat()' calls in 'get_stat_data()'
2009-05-16builtin-checkout: Don't tell user that HEAD has moved before it hasLibravatar Daniel Cordero1-8/+8
Previously, checkout would tell the user this message before moving HEAD, without regard to whether the upcoming move will result in success. If the move failed, this causes confusion. Show the message after the move, unless the move failed. Signed-off-by: Daniel Cordero <theappleman@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-05-12Merge branch 'maint-1.6.2' into maintLibravatar Junio C Hamano1-8/+1
* maint-1.6.2: Revert "checkout branch: prime cache-tree fully"
2009-05-12Revert "checkout branch: prime cache-tree fully"Libravatar Junio C Hamano1-8/+1
The logic in 83ae209 (checkout branch: prime cache-tree fully, 2009-04-20) is bogus; checkout can switch branches with a dirty index and in such a case the tree won't match HEAD. Add t2014-switch to catch this breakage. Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-05-09Teach 'git checkout' to preload the index contentsLibravatar Linus Torvalds1-2/+2
This makes git checkout know to use the threaded index preloading if it is enabled in the config file. You need to have [core] preloadindex = true in your config file to see it, and for that feature to make sense your filesystem needs to be able to do concurrent 'lstat()' lookups, but when that is the case (especially NFS over a high-latency network), this can be a noticeable performance win. But with a low-latency network and at least older Linux NFS clients, this will clearly potentially cause a lot of lock contention. It may still speed up the uncached case, but the threading and locking overhead will result in the cached case likely slowing down. That was almost certainly fixed by Linux commit fc0f684c2 ("NFS: Remove BKL from NFS lookup code"), but that one got merged into 2.6.27-rc1, so older kernel versions than 2.6.27 will not scale very well. But regardless, it's the right thing to do. If your filesystem doesn't scale, don't enable index preloading. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-04-22Merge branch 'jc/maint-read-tree-multi'Libravatar Junio C Hamano1-1/+9
* jc/maint-read-tree-multi: checkout branch: prime cache-tree fully read-tree -m A B: prime cache-tree from the switched-to tree Move prime_cache_tree() to cache-tree.c read-tree A B: do not corrupt cache-tree
2009-04-22Fix typos / spelling in commentsLibravatar Mike Ralphson1-1/+1
Signed-off-by: Mike Ralphson <mike@abacus.co.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-04-20checkout branch: prime cache-tree fullyLibravatar Junio C Hamano1-1/+8
When switching to another branch, the earlier code relied on incremental invalidation of cache-tree entries to degrade it. While it is not wrong per-se, we know that the resulting index must fully match the branch we are switching to unless the -m (merge) option is used. We should simply fully re-prime the cache-tree using the new tree object in such a case. And for safety, invalidate the cache-tree as a whole in other cases. Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-04-20Move prime_cache_tree() to cache-tree.cLibravatar Junio C Hamano1-0/+1
The interface to build cache-tree belongs there. Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-04-18Merge branch 'js/maint-submodule-checkout' into maintLibravatar Junio C Hamano1-3/+0
* js/maint-submodule-checkout: Fix 'git checkout <submodule>' to update the index
2009-04-07Merge branch 'maint'Libravatar Junio C Hamano1-3/+3
* maint: Change double quotes to single quotes in message Documentation: clarify .gitattributes search git-checkout.txt: clarify that <branch> applies when no path is given. git-checkout.txt: fix incorrect statement about HEAD and index Conflicts: Documentation/git-checkout.txt
2009-04-07Change double quotes to single quotes in messageLibravatar Jari Aalto1-3/+3
Most of the time when we give branch name in the message, we quote it inside a pair of single-quotes. git-checkout uses double-quotes; this patch corrects the inconsistency. Signed-off-by: Jari Aalto <jari.aalto@cante.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-04-07Merge branch 'js/maint-submodule-checkout'Libravatar Junio C Hamano1-3/+0
* js/maint-submodule-checkout: Fix 'git checkout <submodule>' to update the index
2009-04-06Merge branch 'jc/name-branch'Libravatar Junio C Hamano1-12/+6
* jc/name-branch: Don't permit ref/branch names to end with ".lock" check_ref_format(): tighten refname rules strbuf_check_branch_ref(): a helper to check a refname for a branch Fix branch -m @{-1} newname check-ref-format --branch: give Porcelain a way to grok branch shorthand strbuf_branchname(): a wrapper for branch name shorthands Rename interpret/substitute nth_last_branch functions Conflicts: Documentation/git-check-ref-format.txt
2009-04-02Fix 'git checkout <submodule>' to update the indexLibravatar Johannes Schindelin1-3/+0
While 'git checkout <submodule>' should not update the submodule's working directory, it should update the index. This is in line with how submodules are handled in the rest of Git. While at it, test 'git reset [<commit>] <submodule>', too. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-03-23builtin-checkout: use warning() instead of fprintf(stderr, "warning: ")Libravatar Miklos Vajna1-2/+2
Signed-off-by: Miklos Vajna <vmiklos@frugalware.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-03-22strbuf_check_branch_ref(): a helper to check a refname for a branchLibravatar Junio C Hamano1-4/+3
This allows a common calling sequence strbuf_branchname(&ref, name); strbuf_splice(&ref, 0, 0, "refs/heads/", 11); if (check_ref_format(ref.buf)) die(...); to be refactored into if (strbuf_check_branch_ref(&ref, name)) die(...); Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-03-22strbuf_branchname(): a wrapper for branch name shorthandsLibravatar Junio C Hamano1-8/+3
The function takes a user-supplied string that is supposed to be a branch name, and puts it in a strbuf after expanding possible shorthand notation. A handful of open coded sequence to do this in the existing code have been changed to use this helper function. Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-03-22Rename interpret/substitute nth_last_branch functionsLibravatar Junio C Hamano1-1/+1
These allow you to say "git checkout @{-2}" to switch to the branch two "branch switching" ago by pretending as if you typed the name of that branch. As it is likely that we will be introducing more short-hands to write the name of a branch without writing it explicitly, rename the functions from "nth_last_branch" to more generic "branch_name", to prepare for different semantics. Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-03-20Merge branch 'mv/parseopt-ls-files'Libravatar Junio C Hamano1-1/+1
* mv/parseopt-ls-files: ls-files: fix broken --no-empty-directory t3000: use test_cmp instead of diff parse-opt: migrate builtin-ls-files. Turn the flags in struct dir_struct into a single variable Conflicts: builtin-ls-files.c t/t3000-ls-files-others.sh
2009-03-04Fix neglect of diff_setup()/diff_setup_done() symmetry.Libravatar Keith Cascio1-0/+2
Code that calls diff_setup(), including via init_revisions(), should later call diff_setup_done(), possibly via setup_revisions(). Failure to do so could cause errors, especially in the future when we add responsibilities to diff_setup_done(). This instance causes no known errors with the present code. But it resulted in an error with an experimental patch. Signed-off-by: Keith Cascio <keith@cs.ucla.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-02-18Turn the flags in struct dir_struct into a single variableLibravatar Johannes Schindelin1-1/+1
By having flags represented as bits in the new member variable 'flags', it will be easier to use parse_options when dir_struct is involved. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-01-28Merge branch 'tr/previous-branch'Libravatar Junio C Hamano1-2/+13
* tr/previous-branch: t1505: remove debugging cruft Simplify parsing branch switching events in reflog Introduce for_each_recent_reflog_ent(). interpret_nth_last_branch(): plug small memleak Fix reflog parsing for a malformed branch switching entry Fix parsing of @{-1}@{1} interpret_nth_last_branch(): avoid traversing the reflog twice checkout: implement "-" abbreviation, add docs and tests sha1_name: support @{-N} syntax in get_sha1() sha1_name: tweak @{-N} lookup checkout: implement "@{-N}" shortcut name for N-th last branch Conflicts: sha1_name.c
2009-01-25Merge branch 'cb/add-pathspec'Libravatar Junio C Hamano1-3/+3
* cb/add-pathspec: remove pathspec_match, use match_pathspec instead clean up pathspec matching
2009-01-17checkout: implement "-" abbreviation, add docs and testsLibravatar Thomas Rast1-0/+3
Have '-' mean the same as '@{-1}', i.e., the last branch we were on. Signed-off-by: Thomas Rast <trast@student.ethz.ch> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-01-17sha1_name: tweak @{-N} lookupLibravatar Thomas Rast1-1/+3
Have the lookup only look at "interesting" checkouts, meaning those that tell you "Already on ..." don't count even though they also cause a reflog entry. Let interpret_nth_last_branch() return the number of characters parsed, so that git-checkout can verify that the branch spec was @{-N}, not @{-1}^2 or something like that. (The latter will be added later.) Signed-off-by: Thomas Rast <trast@student.ethz.ch> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-01-17checkout: implement "@{-N}" shortcut name for N-th last branchLibravatar Junio C Hamano1-2/+8
Implement a shortcut @{-N} for the N-th last branch checked out, that works by parsing the reflog for the message added by previous git-checkout invocations. We expand the @{-N} to the branch name, so that you end up on an attached HEAD on that branch. Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-01-17Move run_hook() from builtin-commit.c into run-command.c (libgit)Libravatar Stephan Beyer1-17/+5
A function that runs a hook is used in several Git commands. builtin-commit.c has the one that is most general for cases without piping. The one in builtin-gc.c prints some useful warnings. This patch moves a merged version of these variants into libgit and lets the other builtins use this libified run_hook(). The run_hook() function used in receive-pack.c feeds the standard input of the pre-receive or post-receive hooks. This function is renamed to run_receive_hook() because the libified run_hook() cannot handle this. Mentored-by: Daniel Barkalow <barkalow@iabervon.org> Mentored-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Stephan Beyer <s-beyer@gmx.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-01-17checkout: don't crash on file checkout before running post-checkout hookLibravatar Stephan Beyer1-2/+4
In the case of git init echo exit >.git/hooks/post-checkout chmod +x .git/hooks/post-checkout touch foo git add foo rm foo git checkout -- foo git-checkout resulted in a Segmentation fault, because there is no new branch set for the post-checkout hook. This patch makes use of the null SHA as it is set for the old branch. While at it, I removed the xstrdup() around the sha1_to_hex(...) calls in builtin-checkout.c/post_checkout_hook() because sha1_to_hex() uses four buffers for the hex-dumped SHA and we only need two. (Duplicating one buffer is only needed if we need more than four.) Signed-off-by: Stephan Beyer <s-beyer@gmx.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-01-14remove pathspec_match, use match_pathspec insteadLibravatar Clemens Buchacher1-3/+3
Both versions have the same functionality. This removes any redundancy. This also adds makes two extensions to match_pathspec: - If pathspec is NULL, return 1. This reflects the behavior of git commands, for which no paths usually means "match all paths". - If seen is NULL, do not use it. Signed-off-by: Clemens Buchacher <drizzd@aon.at> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-01-11Merge branch 'jc/maint-do-not-switch-to-non-commit' into maintLibravatar Junio C Hamano1-1/+1
* jc/maint-do-not-switch-to-non-commit: git checkout: do not allow switching to a tree-ish that is not a commit
2009-01-03Merge branch 'jc/maint-do-not-switch-to-non-commit'Libravatar Junio C Hamano1-1/+1
* jc/maint-do-not-switch-to-non-commit: git checkout: do not allow switching to a tree-ish that is not a commit
2009-01-03git checkout: do not allow switching to a tree-ish that is not a commitLibravatar Junio C Hamano1-1/+1
"git checkout -b newbranch $commit^{tree}" mistakenly created a new branch rooted at the current HEAD, because in that case, the two structure fields used to see if the command was invoked without any argument (hence it needs to default to checking out the HEAD) were populated incorrectly. Upon seeing a command line argument that we took as a rev, we should store that string in new.name, even if that does not name a commit. This will correctly trigger the existing safety logic. Signed-off-by: Junio C Hamano <gitster@pobox.com> Acked-by: Daniel Barkalow <barkalow@iabervon.org>
2008-12-07builtin-checkout.c: check error return from read_cache()Libravatar Junio C Hamano1-2/+5
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-11-27Merge branch 'maint'Libravatar Junio C Hamano1-1/+1
* maint: sha1_file.c: resolve confusion EACCES vs EPERM sha1_file: avoid bogus "file exists" error message git checkout: don't warn about unborn branch if -f is already passed bash: offer refs instead of filenames for 'git revert' bash: remove dashed command leftovers git-p4: fix keyword-expansion regex fast-export: use an unsorted string list for extra_refs Add new testcase to show fast-export does not always exports all tags
2008-11-27git checkout: don't warn about unborn branch if -f is already passedLibravatar Matt McCutchen1-1/+1
I think it's unnecessary to warn that the checkout has been forced due to an unborn current branch if -f has been explicitly passed. For one project, I am using git-new-workdir to create workdirs from a bare repository whose HEAD is set to an unborn branch, and this warning started to irritate me. Signed-off-by: Matt McCutchen <matt@mattmccutchen.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-11-12Merge branch 'maint'Libravatar Junio C Hamano1-2/+1
* maint: Start 1.6.0.5 cycle Fix pack.packSizeLimit and --max-pack-size handling checkout: Fix "initial checkout" detection Remove the period after the git-check-attr summary Conflicts: RelNotes
2008-11-12checkout: Fix "initial checkout" detectionLibravatar Junio C Hamano1-2/+1
Earlier commit 5521883 (checkout: do not lose staged removal, 2008-09-07) tightened the rule to prevent switching branches from losing local changes, so that staged removal of paths can be protected, while attempting to keep a loophole to still allow a special case of switching out of an un-checked-out state. However, the loophole was made a bit too tight, and did not allow switching from one branch (in an un-checked-out state) to check out another branch. The change to builtin-checkout.c in this commit loosens it to allow this, by not insisting the original commit and the new commit to be the same. It also introduces a new function, is_index_unborn (and an associated macro, is_cache_unborn), to check if the repository is truly in an un-checked-out state more reliably, by making sure that $GIT_INDEX_FILE did not exist when populating the in-core index structure. A few places the earlier commit 5521883 added the check for the initial checkout condition are updated to use this function. Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-11-09Merge branch 'maint'Libravatar Junio C Hamano1-4/+4
* maint: Documentation: bisect: change a few instances of "git-cmd" to "git cmd" Documentation: rev-list: change a few instances of "git-cmd" to "git cmd" checkout: Don't crash when switching away from an invalid branch.
2008-11-09checkout: Don't crash when switching away from an invalid branch.Libravatar Alexandre Julliard1-4/+4
When using alternates, it is possible for HEAD to end up pointing to an invalid commit. git checkout should be able to recover from that situation without crashing. Signed-off-by: Alexandre Julliard <julliard@winehq.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-10-19Fix mismerge at cdb22c4 in builtin-checkout.cLibravatar Junio C Hamano1-3/+0
The code to complain when -b is not given but an explicit --track/--no-track override was given from the command line was unchanged on one branch and reworked on the other branch. The merge result incorrectly kept it. Spotted by Matt McCutchen. Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-10-18Merge branch 'db/maint-checkout-b' into maintLibravatar Junio C Hamano1-0/+12
* db/maint-checkout-b: Check early that a new branch is new and valid
2008-10-12Replace calls to strbuf_init(&foo, 0) with STRBUF_INIT initializerLibravatar Brandon Casey1-8/+4
Many call sites use strbuf_init(&foo, 0) to initialize local strbuf variable "foo" which has not been accessed since its declaration. These can be replaced with a static initialization using the STRBUF_INIT macro which is just as readable, saves a function call, and takes up fewer lines. Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>