1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-10-31 22:37:54 +01:00
Commit graph

100 commits

Author SHA1 Message Date
Daniel Barkalow
352eadc400 Check early that a new branch is new and valid
If you fail to update refs to change branches in checkout, your index
and working tree are left already updated. We don't have an easy way
to undo this, but at least we can check things that would make the
creation of a new branch fail. These checks were in the shell version,
and were lost in the C conversion.

The messages are from the shell version, and should probably be made nicer.

[jc: added test to t7201]

Signed-off-by: Daniel Barkalow <barkalow@iabervon.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-09-21 23:17:06 -07:00
Junio C Hamano
2ba3d5d9bd Merge branch 'jc/maint-checkout-keep-remove' into maint
* jc/maint-checkout-keep-remove:
  checkout: do not lose staged removal
2008-09-18 19:53:22 -07:00
Junio C Hamano
578421fbd8 Merge branch 'jc/maint-checkout-keep-remove'
* jc/maint-checkout-keep-remove:
  checkout: do not lose staged removal
2008-09-16 00:49:59 -07:00
Junio C Hamano
94c27881bd Merge branch 'jc/maint-checkout-fix' into maint
* jc/maint-checkout-fix:
  checkout: do not check out unmerged higher stages randomly
2008-09-10 02:13:41 -07:00
Junio C Hamano
5521883490 checkout: do not lose staged removal
The logic to checkout a different commit implements the safety to never
lose user's local changes.  For example, switching from a commit to
another commit, when you have changed a path that is different between
them, need to merge your changes to the version from the switched-to
commit, which you may not necessarily be able to resolve easily.  By
default, "git checkout" refused to switch branches, to give you a chance
to stash your local changes (or use "-m" to merge, accepting the risks of
getting conflicts).

This safety, however, had one deliberate hole since early June 2005.  When
your local change was to remove a path (and optionally to stage that
removal), the command checked out the path from the switched-to commit
nevertheless.

This was to allow an initial checkout to happen smoothly (e.g. an initial
checkout is done by starting with an empty index and switching from the
commit at the HEAD to the same commit).  We can tighten the rule slightly
to allow this special case to pass, without losing sight of removal
explicitly done by the user, by noticing if the index is truly empty when
the operation begins.

For historical background, see:

    http://thread.gmane.org/gmane.comp.version-control.git/4641/focus=4646

This case is marked as *0* in the message, which both Linus and I said "it
feels somewhat wrong but otherwise we cannot start from an empty index".

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-09-09 22:55:22 -07:00
Junio C Hamano
11bd3ddb91 Merge branch 'jc/maint-checkout-fix'
* jc/maint-checkout-fix:
  checkout: do not check out unmerged higher stages randomly

Conflicts:
	t/t7201-co.sh
2008-09-07 22:44:45 -07:00
Junio C Hamano
9b8ae93ad9 Merge branch 'maint'
* maint:
  Start 1.6.0.2 maintenance cycle
  tests: use "git xyzzy" form (t7200 - t9001)
  tests: use "git xyzzy" form (t7000 - t7199)
  Fix passwd(5) ref and reflect that commit doens't use commit-tree
  improve handling of sideband message display
  tests: use "git xyzzy" form (t3600 - t6999)
  tests: use "git xyzzy" form (t0000 - t3599)
  checkout: fix message when leaving detached HEAD
  clone: fix creation of explicitly named target directory
  'git foo' program identifies itself without dash in die() messages
  setup_git_directory(): fix move to worktree toplevel directory
  update-index: fix worktree setup
  Start conforming code to "git subcmd" style
  read-tree: setup worktree if merge is required
  grep: fix worktree setup
  diff*: fix worktree setup

Conflicts:
	RelNotes
	t/t3900-i18n-commit.sh
	t/t7003-filter-branch.sh
2008-09-03 16:08:23 -07:00
Jeff King
bea005e21b checkout: fix message when leaving detached HEAD
The shell version of git checkout would print:

  Previous HEAD position was 1234abcd... commit subject line

when leaving a detached HEAD for another commit. Ths C
version attempted to implement this, but got the condition
wrong such that the behavior never triggered.

This patch simplifies the conditions for showing the message
to the ones used by the shell version: any time we are
leaving a detached HEAD and the new and old commits are not
the same (this suppresses it for the "git checkout -b new"
case recommended when you enter the detached state).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-09-03 12:36:38 -07:00
Junio C Hamano
eac5a40151 checkout --conflict=<style>: recreate merge in a non-default style
This new option does essentially the same thing as -m option when checking
unmerged paths out of the index, but it uses the specified style instead
of configured merge.conflictstyle.

Setting "merge.conflictstyle" to "diff3" is usually less useful than using
the default "merge" style, because the latter allows a conflict that
results by both sides changing the same region in a very similar way to
get simplified substancially by reducing the common lines.  However, when
one side removed a group of lines (perhaps a function was moved to some
other file) while the other side modified it, the default "merge" style
does not give any clue as to why the hunk is left conflicting.  You would
need the original to understand what is going on.

The recommended use would be not to set merge.conflictstyle variable so
that you would usually use the default "merge" style conflict, and when
the result in a path in a particular merge is too hard to understand, use
"git checkout --conflict=diff3 $path" to check it out with the original to
review what is going on.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-08-31 20:09:21 -07:00
Miklos Vajna
8a2fce1895 merge-recursive: introduce merge_options
This makes it possible to avoid passing the labels of branches as
arguments to merge_recursive(), merge_trees() and
merge_recursive_generic().

It also takes care of subtree merge, output buffering, verbosity, and
rename limits - these were global variables till now in
merge-recursive.c.

A new function, named init_merge_options(), is introduced as well, it
clears the struct merge_info, then initializes with default values,
finally updates the default values based on the config and environment
variables.

Signed-off-by: Miklos Vajna <vmiklos@frugalware.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-08-30 20:46:54 -07:00
Junio C Hamano
0cf8581e33 checkout -m: recreate merge when checking out of unmerged index
This teaches git-checkout to recreate a merge out of unmerged
index entries while resolving conflicts.

With this patch, checking out an unmerged path from the index
now have the following possibilities:

 * Without any option, an attempt to checkout an unmerged path
   will atomically fail (i.e. no other cleanly-merged paths are
   checked out either);

 * With "-f", other cleanly-merged paths are checked out, and
   unmerged paths are ignored;

 * With "--ours" or "--theirs, the contents from the specified
   stage is checked out;

 * With "-m" (we should add "--merge" as synonym), the 3-way merge
   is recreated from the staged object names and checked out.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-08-30 19:57:55 -07:00
Junio C Hamano
38901a4837 checkout --ours/--theirs: allow checking out one side of a conflicting merge
This lets you to check out 'our' (or 'their') version of an
unmerged path out of the index while resolving conflicts.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-08-30 19:28:45 -07:00
Junio C Hamano
db9410990e checkout -f: allow ignoring unmerged paths when checking out of the index
Earlier we made "git checkout $pathspec" to atomically refuse
the operation of $pathspec matched any path with unmerged
stages.  This patch allows:

    $ git checkout -f a b c

to ignore, instead of error out on, such unmerged paths.  The
fix to prevent checkout of an unmerged path from random stages
is still there.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-08-30 19:16:12 -07:00
Junio C Hamano
8fdcf31254 checkout: do not check out unmerged higher stages randomly
During a conflicted merge when you have unmerged stages for a
path F in the index, if you said:

    $ git checkout F

we rewrote F as many times as we have stages for it, and the
last one (typically "theirs") was left in the work tree, without
resolving the conflict.

This fixes it by noticing that a specified pathspec pattern
matches an unmerged path, and by erroring out.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-08-30 16:46:25 -07:00
Alex Riesen
9188ed8962 Extend "checkout --track" DWIM to support more cases
The code handles additionally "refs/remotes/<something>/name",
"remotes/<something>/name", and "refs/<namespace>/name".

Signed-off-by: Alex Riesen <raa.lkml@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-08-22 17:18:26 -07:00
Johannes Schindelin
bb0ceb6264 checkout --track: make up a sensible branch name if '-b' was omitted
What does the user most likely want with this command?

	$ git checkout --track origin/next

Exactly.  A branch called 'next', that tracks origin's branch 'next'.
Make it so.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-08-11 16:37:28 -07:00
Pierre Habouzit
859fdabaed git-checkout: improve error messages, detect ambiguities.
The patch is twofold: it moves the option consistency checks just under
the parse_options call so that it doesn't get in the way of the tree
reference vs. pathspecs desambiguation.

The other part rewrites the way to understand arguments so that when
git-checkout fails it does with an understandable message. Compared to the
previous behavior we now have:

  - a better error message when doing:

        git checkout <blob reference> --

    now complains about the reference not pointing to a tree, instead of
    things like:

        error: pathspec <blob reference> did not match any file(s) known to git.
        error: pathspec '--' did not match any file(s) known to git.

  - a better error message when doing:

        git checkout <path> --

    It now complains about <path> not being a reference instead of the
    completely obscure:

        error: pathspec '--' did not match any file(s) known to git.

  - an error when -- wasn't used, and the first argument is ambiguous
    (i.e. can be interpreted as both ref and as path).

Signed-off-by: Pierre Habouzit <madcoder@debian.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-07-24 23:24:00 -07:00
Junio C Hamano
6536034630 Merge branch 'maint' into ph/checkout
* maint:
  git-checkout: fix command line parsing.
2008-07-23 18:42:24 -07:00
Pierre Habouzit
f5242ebf0d git-checkout: fix command line parsing.
This fixes an issue when you use:

    $ git checkout -- <path1> [<paths>...]

and that <path1> can also be understood as a reference. git-checkout
mistakenly understands this as the same as:

    $ git checkout <path1> -- [<paths>...]

because parse-options was eating the '--' and the argument parser thought
he was parsing:

    $ git checkout <path1> [<paths>...]

Where there indeed is an ambiguity

Signed-off-by: Pierre Habouzit <madcoder@debian.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-07-23 12:09:47 -07:00
René Scharfe
671f070721 add context pointer to read_tree_recursive()
Add a pointer parameter to read_tree_recursive(), which is passed to the
callback function.  This allows callers of read_tree_recursive() to
share data with the callback without resorting to global variables.  All
current callers pass NULL.

Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-07-15 07:17:59 -07:00
Junio C Hamano
6d21bf96b5 Refactor "tracking statistics" code used by "git checkout"
People seem to like "Your branch is ahead by N commit" report made by
"git checkout", but the interface into the statistics function was a bit
clunky.  This splits the function into three parts:

 * The core "commit counting" function that takes "struct branch" and
   returns number of commits to show if we are ahead, behind or forked;

 * Convenience "stat formating" function that takes "struct branch" and
   formats the report into a given strbuf, using the above function;

 * "checkout" specific function that takes "branch_info" (type that is
   internal to checkout implementation), calls the above function and
   print the formatted result.

in the hope that the former two can be more easily reusable.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-07-02 23:32:25 -07:00
Junio C Hamano
291d823e36 checkout: "best effort" checkout
When unpack_trees() returned an error while switching branches, we used to
stop right there, exiting without writing the index out or switching HEAD.

This is Ok when unpack_trees() returned an error because it detected
untracked files or locally modified paths that could be overwritten by
branch switching, because that error return is done before we start to
modify the work tree.  But it is undesirable if unpack_trees() already
started to update the work tree and a failure is returned because some but
not all paths are updated in the work tree, perhaps because a directory
that some files need to go in was read-only by mistake, or a file that
will be overwritten by branch switching had a mandatory lock on it and we
failed to unlink it.

This changes the behaviour upon such an error to complete the branch
switching; the files updated in the work tree will hopefully be much more
consistent with the index and HEAD derived from the switched-to branch.

We still issue error messages, and exit the command with non-zero status,
so scripted callers need to notice it.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-05-29 17:35:22 -07:00
Junio C Hamano
6286a08db3 checkout: consolidate reset_{to_new,clean_to_new}()
These two were very similar functions with only tiny bit of difference.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-05-29 17:35:10 -07:00
Junio C Hamano
84a5750bc5 checkout: make reset_clean_to_new() not die by itself
Instead, have its error percolate up through the callchain and let it be
the exit status of the main command.  No semantic changes yet.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-05-28 17:38:21 -07:00
Junio C Hamano
d2b3691b61 "git checkout -- paths..." should error out when paths cannot be written
When "git checkout -- paths..." cannot update work tree for whatever
reason, checkout_entry() correctly issued an error message for the path to
the end user, but the command ignored the error, causing the entire
command to succeed.  This fixes it.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-05-28 17:38:20 -07:00
Junio C Hamano
9bd81e4249 Merge branch 'js/config-cb'
* js/config-cb:
  Provide git_config with a callback-data parameter

Conflicts:

	builtin-add.c
	builtin-cat-file.c
2008-05-25 14:25:02 -07:00
Junio C Hamano
a24d287fb3 Merge branch 'jc/unpack-trees-reword'
* jc/unpack-trees-reword:
  unpack-trees: allow Porcelain to give different error messages
2008-05-25 13:38:27 -07:00
Junio C Hamano
8ccba008ee unpack-trees: allow Porcelain to give different error messages
The plumbing output is sacred as it is an API.  We _could_ change it if it
is broken in such a way that it cannot convey necessary information fully,
but we just do not _reword_ for the sake of rewording.  If somebody does
not like it, s/he is complaining too late.  S/he should have been here in
early May 2005 and make the language used by the API closer to what humans
read.  S/he wasn't here.  Too bad, and it is too late.

And people who complain should look at a bigger picture.  Look at what was
suggested by one of them and think for five seconds:

     $ git checkout mytopic
    -fatal: Entry 'frotz' not uptodate. Cannot merge.
    +fatal: Entry 'frotz' has local changes. Cannot merge.

If you do not see something wrong with this output, your brain has already
been rotten with use of git for too long a time.  Nobody asked us to
"merge" but why are we talking about "Cannot merge"?

This patch introduces a mechanism to allow Porcelains to specify messages
that are different from the ones that is given by the underlying plumbing
implementation of read-tree, so that we can reword the message Porcelains give
without disrupting the output from the plumbing.

    $ git-checkout pu
    error: You have local changes to 'Makefile'; cannot switch branches.

There are other places that ask unpack_trees() to n-way merge, detect
issues  and let it issue error message on its own, but I did this as a
demonstration and replaced only one message.

Yes I know about C99 structure initializers.  I'd love to use them but we
try to be nice to compilers without it.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-05-19 19:30:13 -07:00
Johannes Schindelin
ef90d6d420 Provide git_config with a callback-data parameter
git_config() only had a function parameter, but no callback data
parameter.  This assumes that all callback functions only modify
global variables.

With this patch, every callback gets a void * parameter, and it is hoped
that this will help the libification effort.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-05-14 12:34:44 -07:00
Alex Riesen
7ae02a30e8 Extend interface of add_files_to_cache to allow ignore indexing errors
Signed-off-by: Alex Riesen <raa.lkml@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-05-12 20:54:52 -07:00
Junio C Hamano
471793f91e Merge branch 'maint'
* maint:
  checkout: don't rfc2047-encode oneline on detached HEAD
  filter-branch: Documentation fix.
2008-05-03 22:15:09 -07:00
Jeff King
278863180a checkout: don't rfc2047-encode oneline on detached HEAD
When calling pretty_print_commit, there is an implicit
assumption that passing in a non-NULL "subject" variable
for oneline or email formats means that the output is part
of a subject and therefore "subject" to rfc2047 encoding.
This is not the desired effect when reporting the movement
of detached HEAD.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-05-03 18:47:18 -07:00
Miklos Vajna
498a6e7eaa git checkout: add -t alias for --track
Signed-off-by: Miklos Vajna <vmiklos@frugalware.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-04-27 13:19:33 -07:00
Linus Torvalds
34110cd4e3 Make 'unpack_trees()' have a separate source and destination index
We will always unpack into our own internal index, but we will take the
source from wherever specified, and we will optionally write the result
to a specified index (optionally, because not everybody even _wants_ any
result: the index diffing really wants to just walk the tree and index
in parallel).

This ends up removing a fair number more lines than it adds, for the
simple reason that we can now skip all the crud that tried to be
oh-so-careful about maintaining our position in the index as we were
traversing and modifying it.  Since we don't actually modify the source
index any more, we can just update the 'o->pos' pointer without worrying
about whether an index entry got removed or replaced or added to.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-03-09 01:03:38 -08:00
Linus Torvalds
bc052d7f43 Make 'unpack_trees()' take the index to work on as an argument
This is just a very mechanical conversion, and makes everybody set it to
'&the_index' before calling, but at least it makes it more explicit
where we work with the index.

The next stage would be to split that index usage up into a 'source' and
a 'destination' index, so that we can unpack into a different index than
we started out from.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-03-09 00:43:48 -08:00
Denis Cheng
a3647bee1a cleanup: remove unused git_checkout_config
Directly call git_default_config instead.

Signed-off-by: Denis Cheng <crquan@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-03-02 08:11:44 -08:00
Daniel Barkalow
75336878c7 Write index file on any checkout of files
We need to rewrite the index file when we check out files, even if we
haven't modified the blob info by reading from another tree, so that
we get the stat cache to include the fact that we just modified the
file so it doesn't need to be refreshed.

While we're at it, move everything that needs to be done to check out
some paths from a tree (or the current index) into checkout_paths().

Signed-off-by: Daniel Barkalow <barkalow@iabervon.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-02-29 00:00:29 -08:00
Alex Riesen
301e42edc3 Fix builtin checkout crashing when given an invalid path
Signed-off-by: Alex Riesen <raa.lkml@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-02-29 00:00:29 -08:00
Junio C Hamano
60b188a984 Merge branch 'js/branch-track'
* js/branch-track:
  doc: documentation update for the branch track changes
  branch: optionally setup branch.*.merge from upstream local branches

Conflicts:

	Documentation/config.txt
	Documentation/git-branch.txt
	Documentation/git-checkout.txt
	builtin-branch.c
	cache.h
	t/t7201-co.sh
2008-02-27 13:02:57 -08:00
Junio C Hamano
04c9e11f2c checkout: error out when index is unmerged even with -m
Even when -m is given to allow fallilng back to 3-way merge
while switching branches, we should refuse if the original index
is unmerged.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
Acked-by: Daniel Barkalow <barkalow@iabervon.org>
2008-02-24 00:36:31 -08:00
Junio C Hamano
52229a29c7 checkout: show progress when checkout takes long time while switching branches
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-02-23 15:42:18 -08:00
Junio C Hamano
b56fca07d2 checkout: updates to tracking report
Ask branch_get() for the new branch explicitly instead of
letting it return a potentially stale information.

Tighten the logic to find the tracking branch to deal better
with misconfigured repositories (i.e. branch.*.merge can exist
but it may not have a refspec that fetches to .it)

Also fixes grammar in a message, as pointed out by Jeff King.

The function is about reporting and not automatically
fast-forwarding to the upstream, so stop calling it
"adjust-to".

Signed-off-by: Junio C Hamano <gitster@pobox.com>
Acked-by: Daniel Barkalow <barkalow@iabervon.org>
2008-02-21 15:46:05 -08:00
Daniel Barkalow
75ea38df66 builtin-checkout.c: Remove unused prefix arguments in switch_branches path
This path doesn't actually care where in the tree you started out,
since it must change the whole thing anyway. With the gratuitous bug
removed, the argument is unused.

Signed-off-by: Daniel Barkalow <barkalow@iabervon.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-02-21 15:34:23 -08:00
Junio C Hamano
6010d2d957 checkout: work from a subdirectory
When switching branches from a subdirectory, checkout rewritten
in C extracted the toplevel of the tree in there.

This should fix it.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-02-20 16:07:20 -08:00
Junio C Hamano
b0030db331 checkout: tone down the "forked status" diagnostic messages
When checking out a branch that is behind or forked from a
branch you are building on top of, we used to show full
left-right log but if you already _know_ you have long history
since you forked, it is a bit too much.

This tones down the message quite a bit, by only showing the
number of commits each side has since they diverged.  Also the
message is not shown at all under --quiet.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-02-20 15:36:03 -08:00
Jay Soffian
9ed36cfa35 branch: optionally setup branch.*.merge from upstream local branches
"git branch" and "git checkout -b" now honor --track option even when
the upstream branch is local.  Previously --track was silently ignored
when forking from a local branch.  Also the command did not error out
when --track was explicitly asked for but the forked point specified
was not an existing branch (i.e. when there is no way to set up the
tracking configuration), but now it correctly does.

The configuration setting branch.autosetupmerge can now be set to
"always", which is equivalent to using --track from the command line.
Setting branch.autosetupmerge to "true" will retain the former behavior
of only setting up branch.*.merge for remote upstream branches.

Includes test cases for the new functionality.

Signed-off-by: Jay Soffian <jaysoffian@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-02-19 21:17:45 -08:00
Daniel Barkalow
569012bf91 Clean up reporting differences on branch switch
This also changes it such that:

$ git checkout

will give the same information without changing branches. This is good
for finding out if the fetch you did recently had anything to say
about the branch you've been on, whose name you don't remember at the
moment.

Signed-off-by: Daniel Barkalow <barkalow@iabervon.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-02-19 00:25:52 -08:00
Jay Soffian
b249b552e0 builtin-checkout.c: fix possible usage segfault
Not terminating the options[] array with OPT_END can cause
usage ("git checkout -h") output to segfault.

Signed-off-by: Jay Soffian <jaysoffian@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-02-18 19:19:06 -08:00
Junio C Hamano
79a1e6b432 checkout: notice when the switched branch is behind or forked
When you are switching to a branch that is marked to merge from
somewhere else, e.g. when you have:

    [branch "next"]
            remote = upstream
            merge = refs/heads/next
    [remote "upstream"]
            url = ...
            fetch = refs/heads/*:refs/remotes/linus/*

and you say "git checkout next", the branch you checked out
may be behind, and you may want to update from the upstream
before continuing to work.

This patch makes the command to check the upstream (in this
example, "refs/remotes/linus/next") and our branch "next", and:

    (1) if they match, nothing happens;

    (2) if you are ahead (i.e. the upstream is a strict ancestor
        of you), one line message tells you so;

    (3) otherwise, you are either behind or you and the upstream
        have forked.  One line message will tell you which and
        then you will see a "log --pretty=oneline --left-right".

We could enhance this with an option that tells the command to
check if there is no local change, and automatically fast
forward when you are truly behind.  But I ripped out that change
because I was unsure what the right way should be to allow users
to control it (issues include that checkout should not become
automatically interactive).

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-02-16 17:17:09 -08:00
Daniel Barkalow
782c2d65c2 Build in checkout
The only differences in behavior should be:

 - git checkout -m with non-trivial merging won't print out
   merge-recursive messages (see the change in t7201-co.sh)

 - git checkout -- paths... will give a sensible error message if
   HEAD is invalid as a commit.

 - some intermediate states which were written to disk in the shell
   version (in particular, index states) are only kept in memory in
   this version, and therefore these can no longer be revealed by
   later write operations becoming impossible.

 - when we change branches, we discard MERGE_MSG, SQUASH_MSG, and
   rr-cache/MERGE_RR, like reset always has.

I'm not 100% sure I got the merge recursive setup exactly right; the
base for a non-trivial merge in the shell code doesn't seem
theoretically justified to me, but I tried to match it anyway, and the
tests all pass this way.

Other than these items, the results should be identical to the shell
version, so far as I can tell.

[jc: squashed lock-file fix from Dscho in]

Signed-off-by: Daniel Barkalow <barkalow@iabervon.org>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-02-16 15:05:02 -08:00