summaryrefslogtreecommitdiff
AgeCommit message (Collapse)AuthorFilesLines
2019-05-07checkout: split part of it to new command 'restore'Libravatar Nguyễn Thái Ngọc Duy13-5/+257
Previously the switching branch business of 'git checkout' becomes a new command 'switch'. This adds the restore command for the checking out paths path. Similar to git-switch, a new man page is added to describe what the command will become. The implementation will be updated shortly to match the man page. A couple main differences from 'git checkout <paths>': - 'restore' by default will only update worktree. This matters more when --source is specified ('checkout <tree> <paths>' updates both worktree and index). - 'restore --staged' can be used to restore the index. This command overlaps with 'git reset <paths>'. - both worktree and index could also be restored at the same time (from a tree) when both --staged and --worktree are specified. This overlaps with 'git checkout <tree> <paths>' - default source for restoring worktree and index is the index and HEAD respectively. A different (tree) source could be specified as with --source (*). - when both index and worktree are restored, --source must be specified since the default source for these two individual targets are different (**) - --no-overlay is enabled by default, if an entry is missing in the source, restoring means deleting the entry (*) I originally went with --from instead of --source. I still think --from is a better name. The short option -f however is already taken by force. And I do think short option is good to have, e.g. to write -s@ or -s@^ instead of --source=HEAD. (**) If you sit down and think about it, moving worktree's source from the index to HEAD makes sense, but nobody is really thinking it through when they type the commands. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-04-02doc: promote "git switch"Libravatar Nguyễn Thái Ngọc Duy19-105/+105
The new command "git switch" is added to avoid the confusion of one-command-do-all "git checkout" for new users. They are also helpful to avoid ambiguation context. For these reasons, promote it everywhere possible. This includes documentation, suggestions/advice from other commands... The "Checking out files" progress line in unpack-trees.c is also updated to "Updating files" to be neutral to both git-checkout and git-switch. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-04-02completion: support switchLibravatar Nguyễn Thái Ngọc Duy1-1/+36
Completion support for --guess could be made better. If no --detach is given, we should only provide a list of refs/heads/* and dwim ones, not the entire ref space. But I still can't penetrate that __git_refs() function yet. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-04-02t: add tests for switchLibravatar Nguyễn Thái Ngọc Duy1-0/+96
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-04-02switch: make --orphan switch to an empty treeLibravatar Nguyễn Thái Ngọc Duy1-8/+31
Switching and creating branches always involves knowing the <start-point> to begin the new branch from. Sometimes, people want to create a new branch that does not have any commits yet; --orphan is a flag to allow that. --orphan overrides the default of HEAD for <start-point> instead causing us to start from an empty history with all tracked files removed from the index and working tree. The use of --orphan is incompatible with specifying a <start-point>. A note on the implementation. An alternative is just create a dummy commit in-core with empty tree and switch to it. But there's a chance the commit's SHA-1 may end up somewhere permanent like reflog. It's best to make sure "commit" pointer is NULL to avoid it. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-04-02switch: reject if some operation is in progressLibravatar Nguyễn Thái Ngọc Duy1-0/+40
Unless you know what you're doing, switching to another branch to do something then switching back could be confusing. Worse, you may even forget that you're in the middle of something. By the time you realize, you may have done a ton of work and it gets harder to go back. A new option --ignore-in-progress was considered but dropped because it was not exactly clear what should happen. Sometimes you can switch away and get back safely and resume the operation. Sometimes not. And the git-checkout behavior is automatically clear merge/revert/cherry-pick, which makes it a bit even more confusing [1]. We may revisit and add this option in the future. But for now play it safe and not allow it (you can't even skip this check with --force). The user is suggested to cancel the operation by themselves (and hopefully they do consider the consequences, not blindly type the command), or to create a separate worktree instead of switching. The third option is the good old "git checkout", but it's not mentioned. [1] CACsJy8Axa5WsLSjiscjnxVK6jQHkfs-gH959=YtUvQkWriAk5w@mail.gmail.com Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-04-02switch: no worktree status unless real branch switch happensLibravatar Nguyễn Thái Ngọc Duy3-148/+8
When we switch from one branch to another, it makes sense to show a summary of local changes since there could be conflicts, or some files left modified.... When switch is used solely for creating a new branch (and "switch" to the same commit) or detaching, we don't really need to show anything. "git checkout" does it anyway for historical reasons. But we can start with a clean slate with switch and don't have to. This essentially reverts fa655d8411 (checkout: optimize "git checkout -b <new_branch>" - 2018-08-16) and make it default for switch, but also for -B and --detach. Users of big repos are encouraged to move to switch. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-04-02switch: implicit dwim, use --no-guess to disable itLibravatar Nguyễn Thái Ngọc Duy2-23/+31
This is already the default in git-checkout. The real change in here is just minor cleanup. The main excuse is to explain why dwim is kept default. Contrary to detach mode that is easy to get into and confusing to get back out. Automatically creating a tracking branch often does not kick in as often (you would need a branch of the same name on a remote). And since the branch creation is reported clearly, the user should be able to undo/delete it if it's unwanted. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-04-02switch: add short option for --detachLibravatar Nguyễn Thái Ngọc Duy1-1/+1
"git checkout" automatically detaches branches and --detach is not that useful (--no-detach is more likely). But for "switch", you may want to use it more often once you're used to detached HEAD. This of course adds -d to git-checkout but it does not harm (yet?) to do it. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-04-02switch: only allow explicit detached HEADLibravatar Nguyễn Thái Ngọc Duy1-0/+34
"git checkout <commit>" will checkout the commit in question and detach HEAD from the current branch. It is naturally a right thing to do once you get git references. But detached HEAD is a scary concept to new users because we show a lot of warnings and stuff, and it could be hard to get out of (until you know better). To keep switch a bit more friendly to new users, we only allow entering detached HEAD mode when --detach is given. "git switch" must take a branch (unless you create a new branch, then of course switch can take any commit-ish) Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-04-02switch: reject "do nothing" caseLibravatar Nguyễn Thái Ngọc Duy1-0/+9
"git checkout" can be executed without any arguments. What it does is not exactly great: it switches from HEAD to HEAD and shows worktree modification as a side effect. Make switch reject this case. Just use "git status" if you want that side effect. For switch, you have to either - really switch a branch - (explicitly) detach from the current branch - create a new branch Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-04-02switch: stop accepting pathspecLibravatar Nguyễn Thái Ngọc Duy1-5/+15
This command is about switching branch (or creating a new one) and should not accept pathspec. This helps simplify ambiguation handling. The other two ("git checkout" and "git restore") of course do accept pathspec as before. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-04-02switch: remove -lLibravatar Nguyễn Thái Ngọc Duy1-1/+1
This option is ancient. Nowadays reflog is enabled by default and automatically created for new branches. Keep it in git-checkout only. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-04-02switch: add --discard-changesLibravatar Nguyễn Thái Ngọc Duy1-2/+10
--discard-changes is a better name than --force for this option since it's what really happens. --force is turned to an alias for --discard-changes. But it's meant to be an alias for potentially more force options in the future. Side note. It's not obvious from the patch but --discard-changes also affects submodules if --recurse-submodules is used. The knob to force updating submodules is hidden behind unpack-trees.c Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-04-02switch: better names for -b and -BLibravatar Nguyễn Thái Ngọc Duy1-11/+21
The shortcut of these options do not make much sense when used with switch. And their descriptions are also tied to checkout. Move -b/-B to cmd_checkout() and new -c/-C with the same functionality in cmd_switch_branch() Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-04-02checkout: split part of it to new command 'switch'Libravatar Nguyễn Thái Ngọc Duy14-27/+353
"git checkout" doing too many things is a source of confusion for many users (and it even bites old timers sometimes). To remedy that, the command will be split into two new ones: switch and restore. The good old "git checkout" command is still here and will be until all (or most of users) are sick of it. See the new man page for the final design of switch. The actual implementation though is still pretty much the same as "git checkout" and not completely aligned with the man page. Following patches will adjust their behavior to match the man page. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-04-02checkout: split options[] array in three piecesLibravatar Nguyễn Thái Ngọc Duy3-23/+77
This is a preparation step for introducing new commands that do parts of what checkout does. There will be two new commands, one is about switching branches, detaching HEAD... one about checking out paths. These share the a subset of command line options. The rest of command line options are separate. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-04-02checkout: move 'confict_style' and 'dwim_..' to checkout_optsLibravatar Nguyễn Thái Ngọc Duy1-7/+10
These local variables are referenced by struct option[]. This struct will soon be broken down, moved away and we can't rely on local variables anymore. Move these two to struct checkout_opts in preparation for that. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-04-02checkout: make "opts" in cmd_checkout() a pointerLibravatar Nguyễn Thái Ngọc Duy1-57/+58
"opts" will soon be moved out of cmd_checkout(). To keep changes in that patch smaller, convert "opts" to a pointer and keep the real thing behind "real_opts". Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-04-02checkout: factor out some code in parse_branchname_arg()Libravatar Nguyễn Thái Ngọc Duy1-20/+31
This is in preparation for the new command restore, which also needs to parse opts->source_tree but does not need all the disambiguation logic. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-04-02checkout: keep most #include sortedLibravatar Nguyễn Thái Ngọc Duy1-17/+17
The include list becomes very long and frankly a bit unorganized. With the exception of builtin.h, cache.h or git-compat-util.h which have to come first, keep the rest sorted. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-04-02checkout: inform the user when removing branch stateLibravatar Nguyễn Thái Ngọc Duy7-11/+14
After a successful switch, if a merge, cherry-pick or revert is ongoing, it is canceled. This behavior has been with us from the very early beginning, soon after git-merge was created but never actually documented [1]. It may be a good idea to be transparent and tell the user if some operation is canceled. I consider this a better way of telling the user than just adding a sentence or two in git-checkout.txt, which will be mostly ignored anyway. PS. Originally I wanted to print more details like warning: cancelling an in-progress merge from <SHA-1> which may allow some level of undo if the user wants to. But that seems a lot more work. Perhaps it can be improved later if people still want that. [1] ... and I will try not to argue whether it is a sensible behavior. There is some more discussion here if people are interested: CACsJy8Axa5WsLSjiscjnxVK6jQHkfs-gH959=YtUvQkWriAk5w@mail.gmail.com Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-04-02checkout: advice how to get out of detached HEAD modeLibravatar Nguyễn Thái Ngọc Duy2-4/+25
Detached HEAD mode is considered dangerous and confusing for newcomers and we print a big block of warning how to move forward. But we should also suggest the user the way to get out of it if they get into detached HEAD by mistake. While at there, I also suggest how to turn the advice off. This is another thing I find annoying with advices and should be dealt with in a more generic way. But that may require some refactoring in advice.c first. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-04-02t: rename t2014-switch.sh to t2014-checkout-switch.shLibravatar Nguyễn Thái Ngọc Duy1-0/+0
The old name does not really say that this is about 'checkout -b'. See 49d833dc07 (Revert "checkout branch: prime cache-tree fully" - 2009-05-12) for more information Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-04-02git-checkout.txt: fix monospace typesetLibravatar Nguyễn Thái Ngọc Duy1-81/+81
Add backticks where we have none, replace single quotes with backticks and replace double-quotes. Drop double-quotes from nested constructions such as `"@{-1}"`. Helped-by: Martin Ågren <martin.agren@gmail.com> Signed-off-by: Martin Ågren <martin.agren@gmail.com> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-04-02doc: document --overwrite-ignoreLibravatar Nguyễn Thái Ngọc Duy2-0/+11
I added this option in git-checkout and git-merge in c1d7036b6b (checkout,merge: disallow overwriting ignored files with --no-overwrite-ignore - 2011-11-27) but did not remember to update documentation. This completes that commit. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-04-02git-checkout.txt: fix one syntax lineLibravatar Nguyễn Thái Ngọc Duy1-1/+1
<branch> can be omitted in this syntax, and it's actually documented a few paragraphs down: You could omit <branch>, in which case the command degenerates to "check out the current branch", which is a glorified no-op with rather expensive side-effects to show only the tracking information, if exists, for the current branch. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-04-02git-checkout.txt: spell out --no-optionLibravatar Nguyễn Thái Ngọc Duy1-4/+7
It's easier to search for and also less cryptic. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-03-11The second batchLibravatar Junio C Hamano1-0/+22
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-03-11Sync with maintLibravatar Junio C Hamano1-1/+1
* maint: mingw: allow building with an MSYS2 runtime v3.x
2019-03-11Merge branch 'js/rebase-recreate-merge'Libravatar Junio C Hamano1-1/+1
Docfix. * js/rebase-recreate-merge: rebase docs: fix "gitlink" typo
2019-03-11Merge branch 'js/untravis-windows'Libravatar Junio C Hamano2-113/+0
Dev support. * js/untravis-windows: travis: remove the hack to build the Windows job on Azure Pipelines
2019-03-11Merge branch 'rd/gc-prune-doc-fix'Libravatar Junio C Hamano1-1/+1
Doxfix. * rd/gc-prune-doc-fix: docs/git-gc: fix typo "--prune=all" to "--prune=now"
2019-03-11Merge branch 'js/find-lib-h-with-ls-files-when-possible'Libravatar Junio C Hamano1-2/+3
The Makefile uses 'find' utility to enumerate all the *.h header files, which is expensive on platforms with slow filesystems; it now optionally uses "ls-files" if working within a repository, which is a trick similar to how all sources are enumerated to run ETAGS on. * js/find-lib-h-with-ls-files-when-possible: Makefile: use `git ls-files` to list header files, if possible
2019-03-11Merge branch 'rj/hdr-check-gcrypt-fix'Libravatar Junio C Hamano1-1/+4
The set of header files used by "make hdr-check" unconditionally included sha256/gcrypt.h, even when it is not used, causing the make target to fail. We now skip it when GCRYPT_SHA256 is not in use. * rj/hdr-check-gcrypt-fix: Makefile: fix 'hdr-check' when GCRYPT not installed
2019-03-11Merge branch 'jk/guard-bswap-header'Libravatar Junio C Hamano1-0/+5
The include file compat/bswap.h has been updated so that it is safe to (accidentally) include it more than once. * jk/guard-bswap-header: compat/bswap: add include header guards
2019-03-11Merge branch 'rd/attr.c-comment-typofix'Libravatar Junio C Hamano1-4/+4
In-code comment typofix. * rd/attr.c-comment-typofix: attr.c: ".gitattribute" -> ".gitattributes" (comments)
2019-03-11Merge branch 'yb/utf-16le-bom-spellfix'Libravatar Junio C Hamano1-1/+1
Doc update. * yb/utf-16le-bom-spellfix: gitattributes.txt: fix typo
2019-03-11mingw: allow building with an MSYS2 runtime v3.xLibravatar Johannes Schindelin1-1/+1
Recently the Git for Windows project started the upgrade process to a MSYS2 runtime version based on Cygwin v3.x. This has the very notable consequence that `$(uname -r)` no longer reports a version starting with "2", but a version with "3". That breaks our build, as df5218b4c30b (config.mak.uname: support MSys2, 2016-01-13) simply did not expect the version reported by `uname -r` to depend on the underlying Cygwin version: it expected the reported version to match the "2" in "MSYS2". So let's invert that test case to test for *anything else* than a version starting with "1" (for MSys). That should safeguard us for the future, even if Cygwin ends up releasing versionsl like 314.272.65536. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-03-08mingw: drop MakeMaker referenceLibravatar Johannes Schindelin1-1/+0
In 20d2a30f8ffe (Makefile: replace perl/Makefile.PL with simple make rules, 2017-12-10), Git stopped using MakeMaker. Therefore, that definition in the MINGW-specific section became useless. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Reviewed-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-03-07Start 2.22 cycleLibravatar Junio C Hamano3-2/+81
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-03-07Merge branch 'jt/http-auth-proto-v2-fix'Libravatar Junio C Hamano4-207/+213
Unify RPC code for smart http in protocol v0/v1 and v2, which fixes a bug in the latter (lack of authentication retry) and generally improves the code base. * jt/http-auth-proto-v2-fix: remote-curl: use post_rpc() for protocol v2 also remote-curl: refactor reading into rpc_state's buf remote-curl: reduce scope of rpc_state.result remote-curl: reduce scope of rpc_state.stdin_preamble remote-curl: reduce scope of rpc_state.argv
2019-03-07Merge branch 'jk/diff-no-index-initialize'Libravatar Junio C Hamano4-17/+21
"git diff --no-index" may still want to access Git goodies like --ext-diff and --textconv, but so far these have been ignored, which has been corrected. * jk/diff-no-index-initialize: diff: reuse diff setup for --no-index case
2019-03-07Merge branch 'nd/no-more-check-racy'Libravatar Junio C Hamano1-28/+0
Unused code removal. * nd/no-more-check-racy: Delete check-racy.c
2019-03-07Merge branch 'rd/doc-hook-used-in-sample'Libravatar Junio C Hamano1-0/+4
Doc update. * rd/doc-hook-used-in-sample: mention use of "hooks.allownonascii" in "man githooks"
2019-03-07Merge branch 'nd/diff-parseopt-2'Libravatar Junio C Hamano2-211/+319
Second batch to teach the diff machinery to use the parse-options API. * nd/diff-parseopt-2: (21 commits) diff-parseopt: convert --ignore-some-changes diff-parseopt: convert --[no-]minimal diff-parseopt: convert --relative diff-parseopt: convert --no-renames|--[no--rename-empty diff-parseopt: convert --find-copies-harder diff-parseopt: convert -C|--find-copies diff-parseopt: convert -D|--irreversible-delete diff-parseopt: convert -M|--find-renames diff-parseopt: convert -B|--break-rewrites diff-parseopt: convert --output-* diff-parseopt: convert --[no-]compact-summary diff-parseopt: convert --stat* diff-parseopt: convert -s|--no-patch diff-parseopt: convert --name-status diff-parseopt: convert --name-only diff-parseopt: convert --patch-with-stat diff-parseopt: convert --summary diff-parseopt: convert --check diff-parseopt: convert --dirstat and friends diff-parseopt: convert --numstat and --shortstat ...
2019-03-07Merge branch 'en/merge-options-doc'Libravatar Junio C Hamano1-3/+8
Doc update. * en/merge-options-doc: merge-options.txt: correct wording of --no-commit option
2019-03-07Merge branch 'nd/completion-more-parameters'Libravatar Junio C Hamano18-4/+126
The command line completion (in contrib/) has been taught to complete more subcommand parameters. * nd/completion-more-parameters: completion: add more parameter value completion
2019-03-07Merge branch 'ab/receive-pack-use-after-free-fix'Libravatar Junio C Hamano1-8/+15
Memfix. * ab/receive-pack-use-after-free-fix: receive-pack: fix use-after-free bug
2019-03-07Merge branch 'dl/doc-submodule-wo-subcommand'Libravatar Junio C Hamano2-1/+6
Doc update. * dl/doc-submodule-wo-subcommand: submodule: document default behavior