summaryrefslogtreecommitdiff
path: root/builtin-checkout.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2008-08-30 14:46:55 (GMT)
committerJunio C Hamano <gitster@pobox.com>2008-08-31 02:16:12 (GMT)
commitdb9410990ee41f2b253763621c0023c782ec86e2 (patch)
tree59a1b964e8437f0a06e9a4f2bbcb638849f18e2b /builtin-checkout.c
parent8fdcf3125465f70c0cad5be5ab192d46e46307c7 (diff)
downloadgit-db9410990ee41f2b253763621c0023c782ec86e2.zip
git-db9410990ee41f2b253763621c0023c782ec86e2.tar.gz
git-db9410990ee41f2b253763621c0023c782ec86e2.tar.bz2
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>
Diffstat (limited to 'builtin-checkout.c')
-rw-r--r--builtin-checkout.c41
1 files changed, 23 insertions, 18 deletions
diff --git a/builtin-checkout.c b/builtin-checkout.c
index 8544010..1303f3b 100644
--- a/builtin-checkout.c
+++ b/builtin-checkout.c
@@ -20,6 +20,17 @@ static const char * const checkout_usage[] = {
NULL,
};
+struct checkout_opts {
+ int quiet;
+ int merge;
+ int force;
+ int writeout_error;
+
+ const char *new_branch;
+ int new_branch_log;
+ enum branch_track track;
+};
+
static int post_checkout_hook(struct commit *old, struct commit *new,
int changed)
{
@@ -85,7 +96,8 @@ static int skip_same_name(struct cache_entry *ce, int pos)
}
-static int checkout_paths(struct tree *source_tree, const char **pathspec)
+static int checkout_paths(struct tree *source_tree, const char **pathspec,
+ struct checkout_opts *opts)
{
int pos;
struct checkout state;
@@ -122,8 +134,12 @@ static int checkout_paths(struct tree *source_tree, const char **pathspec)
if (pathspec_match(pathspec, NULL, ce->name, 0)) {
if (!ce_stage(ce))
continue;
- errs = 1;
- error("path '%s' is unmerged", ce->name);
+ if (opts->force) {
+ warning("path '%s' is unmerged", ce->name);
+ } else {
+ errs = 1;
+ error("path '%s' is unmerged", ce->name);
+ }
pos = skip_same_name(ce, pos) - 1;
}
}
@@ -178,17 +194,6 @@ static void describe_detached_head(char *msg, struct commit *commit)
strbuf_release(&sb);
}
-struct checkout_opts {
- int quiet;
- int merge;
- int force;
- int writeout_error;
-
- char *new_branch;
- int new_branch_log;
- enum branch_track track;
-};
-
static int reset_tree(struct tree *tree, struct checkout_opts *o, int worktree)
{
struct unpack_trees_options opts;
@@ -554,15 +559,15 @@ no_reference:
die("invalid path specification");
/* Checkout paths */
- if (opts.new_branch || opts.force || opts.merge) {
+ if (opts.new_branch || opts.merge) {
if (argc == 1) {
- die("git checkout: updating paths is incompatible with switching branches/forcing\nDid you intend to checkout '%s' which can not be resolved as commit?", argv[0]);
+ die("git checkout: updating paths is incompatible with switching branches.\nDid you intend to checkout '%s' which can not be resolved as commit?", argv[0]);
} else {
- die("git checkout: updating paths is incompatible with switching branches/forcing");
+ die("git checkout: updating paths is incompatible with switching branches.");
}
}
- return checkout_paths(source_tree, pathspec);
+ return checkout_paths(source_tree, pathspec, &opts);
}
if (new.name && !new.commit) {