aboutsummaryrefslogtreecommitdiff
path: root/builtin-revert.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2008-03-02 23:59:50 -0800
committerJunio C Hamano <gitster@pobox.com>2008-03-02 23:59:50 -0800
commit6b48990354b6380665565f21c3f89d2f7109c459 (patch)
treec3eefde8d65ef12c7af7a68ba045cc55f98cd2b8 /builtin-revert.c
parent34cd62eb91600109378c8121c1fecd924a9af177 (diff)
parentd3df4271b900c9bf529cf495afeb77fbbf621221 (diff)
downloadgit-6b48990354b6380665565f21c3f89d2f7109c459.tar.gz
git-6b48990354b6380665565f21c3f89d2f7109c459.tar.xz
Merge branch 'maint'
* maint: Update draft release notes for 1.5.4.4 revert: actually check for a dirty index tests: introduce test_must_fail git-submodule: Fix typo 'url' which should be '$url' receive-pack: Initialize PATH to include exec-dir. Conflicts: builtin-revert.c
Diffstat (limited to 'builtin-revert.c')
-rw-r--r--builtin-revert.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/builtin-revert.c b/builtin-revert.c
index b6dee6a56..607a2f033 100644
--- a/builtin-revert.c
+++ b/builtin-revert.c
@@ -9,6 +9,8 @@
#include "utf8.h"
#include "parse-options.h"
#include "cache-tree.h"
+#include "diff.h"
+#include "revision.h"
/*
* This implements the builtins revert and cherry-pick.
@@ -246,6 +248,17 @@ static char *help_msg(const unsigned char *sha1)
return helpbuf;
}
+static int index_is_dirty(void)
+{
+ struct rev_info rev;
+ init_revisions(&rev, NULL);
+ setup_revisions(0, NULL, &rev, "HEAD");
+ DIFF_OPT_SET(&rev.diffopt, QUIET);
+ DIFF_OPT_SET(&rev.diffopt, EXIT_WITH_STATUS);
+ run_diff_index(&rev, 1);
+ return !!DIFF_OPT_TST(&rev.diffopt, HAS_CHANGES);
+}
+
static int revert_or_cherry_pick(int argc, const char **argv)
{
unsigned char head[20];
@@ -274,12 +287,11 @@ static int revert_or_cherry_pick(int argc, const char **argv)
if (write_cache_as_tree(head, 0, NULL))
die ("Your index file is unmerged.");
} else {
- struct wt_status s;
-
if (get_sha1("HEAD", head))
die ("You do not have a valid HEAD");
- wt_status_prepare(&s);
- if (s.commitable)
+ if (read_cache() < 0)
+ die("could not read the index");
+ if (index_is_dirty())
die ("Dirty index: cannot %s", me);
discard_cache();
}