summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2012-10-23 15:42:09 -0500
committerEdward Thomson <ethomson@edwardthomson.com>2012-10-24 20:24:37 -0500
commit632d8b230bf38cc61cd70b55a54ae2f52502b4af (patch)
tree38a8c4825ab59511951b586edb434a5240f3dc9f /src
parent6f6b0c013c6eff2aca2a7ada1027044f2e20f578 (diff)
downloadlibgit2-632d8b230bf38cc61cd70b55a54ae2f52502b4af.tar.gz
reset changes for merge
Diffstat (limited to 'src')
-rw-r--r--src/merge.c48
-rw-r--r--src/merge.h19
-rw-r--r--src/refs.h3
-rw-r--r--src/repository.c28
-rw-r--r--src/reset.c12
5 files changed, 106 insertions, 4 deletions
diff --git a/src/merge.c b/src/merge.c
new file mode 100644
index 000000000..135af6a8c
--- /dev/null
+++ b/src/merge.c
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2009-2012 the libgit2 contributors
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
+
+#include "repository.h"
+#include "buffer.h"
+#include "merge.h"
+#include "refs.h"
+#include "git2/repository.h"
+#include "git2/merge.h"
+#include "git2/reset.h"
+
+int git_merge__cleanup(git_repository *repo)
+{
+ int error = 0;
+ git_buf merge_head_path = GIT_BUF_INIT,
+ merge_mode_path = GIT_BUF_INIT,
+ merge_msg_path = GIT_BUF_INIT;
+
+ assert(repo);
+
+ if (git_buf_joinpath(&merge_head_path, repo->path_repository, GIT_MERGE_HEAD_FILE) < 0 ||
+ git_buf_joinpath(&merge_mode_path, repo->path_repository, GIT_MERGE_MODE_FILE) < 0 ||
+ git_buf_joinpath(&merge_mode_path, repo->path_repository, GIT_MERGE_MODE_FILE) < 0)
+ return -1;
+
+ if (git_path_isfile(merge_head_path.ptr)) {
+ if ((error = p_unlink(merge_head_path.ptr)) < 0)
+ goto cleanup;
+ }
+
+ if (git_path_isfile(merge_mode_path.ptr))
+ (void)p_unlink(merge_mode_path.ptr);
+
+ if (git_path_isfile(merge_msg_path.ptr))
+ (void)p_unlink(merge_msg_path.ptr);
+
+cleanup:
+ git_buf_free(&merge_msg_path);
+ git_buf_free(&merge_mode_path);
+ git_buf_free(&merge_head_path);
+
+ return error;
+}
+
diff --git a/src/merge.h b/src/merge.h
new file mode 100644
index 000000000..2117d9214
--- /dev/null
+++ b/src/merge.h
@@ -0,0 +1,19 @@
+/*
+ * Copyright (C) 2009-2012 the libgit2 contributors
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
+#ifndef INCLUDE_merge_h__
+#define INCLUDE_merge_h__
+
+#include "git2/types.h"
+
+#define GIT_MERGE_MSG_FILE "MERGE_MSG"
+#define GIT_MERGE_MODE_FILE "MERGE_MODE"
+
+#define MERGE_CONFIG_FILE_MODE 0666
+
+int git_merge__cleanup(git_repository *repo);
+
+#endif
diff --git a/src/refs.h b/src/refs.h
index 54359f07b..58e2fd558 100644
--- a/src/refs.h
+++ b/src/refs.h
@@ -28,8 +28,11 @@
#define GIT_PACKEDREFS_FILE_MODE 0666
#define GIT_HEAD_FILE "HEAD"
+#define GIT_ORIG_HEAD_FILE "ORIG_HEAD"
#define GIT_FETCH_HEAD_FILE "FETCH_HEAD"
#define GIT_MERGE_HEAD_FILE "MERGE_HEAD"
+#define GIT_REVERT_HEAD_FILE "REVERT_HEAD"
+#define GIT_CHERRY_PICK_HEAD_FILE "CHERRY_PICK_HEAD"
#define GIT_REFS_HEADS_MASTER_FILE GIT_REFS_HEADS_DIR "master"
#define GIT_REFNAME_MAX 1024
diff --git a/src/repository.c b/src/repository.c
index 43e0eda8f..fa4604bee 100644
--- a/src/repository.c
+++ b/src/repository.c
@@ -20,6 +20,7 @@
#include "filter.h"
#include "odb.h"
#include "remote.h"
+#include "merge.h"
#define GIT_FILE_CONTENT_PREFIX "gitdir:"
@@ -1348,15 +1349,13 @@ int git_repository_head_tree(git_tree **tree, git_repository *repo)
return 0;
}
-#define MERGE_MSG_FILE "MERGE_MSG"
-
int git_repository_message(char *buffer, size_t len, git_repository *repo)
{
git_buf buf = GIT_BUF_INIT, path = GIT_BUF_INIT;
struct stat st;
int error;
- if (git_buf_joinpath(&path, repo->path_repository, MERGE_MSG_FILE) < 0)
+ if (git_buf_joinpath(&path, repo->path_repository, GIT_MERGE_MSG_FILE) < 0)
return -1;
if ((error = p_stat(git_buf_cstr(&path), &st)) < 0) {
@@ -1382,7 +1381,7 @@ int git_repository_message_remove(git_repository *repo)
git_buf path = GIT_BUF_INIT;
int error;
- if (git_buf_joinpath(&path, repo->path_repository, MERGE_MSG_FILE) < 0)
+ if (git_buf_joinpath(&path, repo->path_repository, GIT_MERGE_MSG_FILE) < 0)
return -1;
error = p_unlink(git_buf_cstr(&path));
@@ -1541,3 +1540,24 @@ cleanup:
git_reference_free(new_head);
return error;
}
+
+int git_repository_state(git_repository *repo)
+{
+ git_buf repo_path = GIT_BUF_INIT;
+ int state = GIT_REPOSITORY_STATE_NONE;
+
+ assert(repo);
+
+ if (git_buf_puts(&repo_path, repo->path_repository) < 0)
+ return -1;
+
+ if (git_path_contains_file(&repo_path, GIT_MERGE_HEAD_FILE))
+ state = GIT_REPOSITORY_STATE_MERGE;
+ else if(git_path_contains_file(&repo_path, GIT_REVERT_HEAD_FILE))
+ state = GIT_REPOSITORY_STATE_REVERT;
+ else if(git_path_contains_file(&repo_path, GIT_CHERRY_PICK_HEAD_FILE))
+ state = GIT_REPOSITORY_STATE_CHERRY_PICK;
+
+ git_buf_free(&repo_path);
+ return state;
+}
diff --git a/src/reset.c b/src/reset.c
index 560ae17b1..aff5b9f88 100644
--- a/src/reset.c
+++ b/src/reset.c
@@ -8,8 +8,10 @@
#include "common.h"
#include "commit.h"
#include "tag.h"
+#include "merge.h"
#include "git2/reset.h"
#include "git2/checkout.h"
+#include "git2/merge.h"
#define ERROR_MSG "Cannot perform reset"
@@ -88,6 +90,11 @@ int git_reset(
goto cleanup;
}
+ if (reset_type == GIT_RESET_SOFT && (git_repository_state(repo) == GIT_REPOSITORY_STATE_MERGE)) {
+ giterr_set(GITERR_OBJECT, "%s (soft) while in the middle of a merge.", ERROR_MSG);
+ goto cleanup;
+ }
+
//TODO: Check for unmerged entries
if (update_head(repo, commit) < 0)
@@ -118,6 +125,11 @@ int git_reset(
goto cleanup;
}
+ if ((error = git_merge__cleanup(repo)) < 0) {
+ giterr_set(GITERR_INDEX, "%s - Failed to clean up merge data.", ERROR_MSG);
+ goto cleanup;
+ }
+
if (reset_type == GIT_RESET_MIXED) {
error = 0;
goto cleanup;