Commit 8a1479a5 by Vicent Martí

Merge pull request #796 from nulltoken/topic/git-stash

Stash
parents a0ce87c5 e4c64cf2
......@@ -52,5 +52,6 @@
#include "git2/reset.h"
#include "git2/message.h"
#include "git2/pack.h"
#include "git2/stash.h"
#endif
......@@ -59,6 +59,7 @@ typedef enum {
GITERR_SSL,
GITERR_SUBMODULE,
GITERR_THREAD,
GITERR_STASH,
} git_error_t;
/**
......
......@@ -347,6 +347,14 @@ GIT_EXTERN(int) git_index_entry_stage(const git_index_entry *entry);
*/
GIT_EXTERN(int) git_index_read_tree(git_index *index, git_tree *tree);
/**
* Get the repository this index relates to
*
* @param index The index
* @return A pointer to the repository
*/
GIT_EXTERN(git_repository *) git_index_owner(const git_index *index);
/** @} */
GIT_END_DECL
#endif
......@@ -97,9 +97,9 @@ GIT_EXTERN(const git_reflog_entry *) git_reflog_entry_byindex(git_reflog *reflog
/**
* Remove an entry from the reflog by its index
*
* To ensure there's no gap in the log history, set the `rewrite_previosu_entry` to 1.
* When deleting entry `n`, member old_oid of entry `n-1` (if any) will be updated with
* the value of memeber new_oid of entry `n+1`.
* To ensure there's no gap in the log history, set `rewrite_previous_entry`
* param value to 1. When deleting entry `n`, member old_oid of entry `n-1`
* (if any) will be updated with the value of member new_oid of entry `n+1`.
*
* @param reflog a previously loaded reflog.
*
......
/*
* 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_git_stash_h__
#define INCLUDE_git_stash_h__
#include "common.h"
#include "types.h"
/**
* @file git2/stash.h
* @brief Git stash management routines
* @ingroup Git
* @{
*/
GIT_BEGIN_DECL
enum {
GIT_STASH_DEFAULT = 0,
/* All changes already added to the index
* are left intact in the working directory
*/
GIT_STASH_KEEP_INDEX = (1 << 0),
/* All untracked files are also stashed and then
* cleaned up from the working directory
*/
GIT_STASH_INCLUDE_UNTRACKED = (1 << 1),
/* All ignored files are also stashed and then
* cleaned up from the working directory
*/
GIT_STASH_INCLUDE_IGNORED = (1 << 2),
};
/**
* Save the local modifications to a new stash.
*
* @param out Object id of the commit containing the stashed state.
* This commit is also the target of the direct reference refs/stash.
*
* @param repo The owning repository.
*
* @param stasher The identity of the person performing the stashing.
*
* @param message Optional description along with the stashed state.
*
* @param flags Flags to control the stashing process.
*
* @return 0 on success, GIT_ENOTFOUND where there's nothing to stash,
* or error code.
*/
GIT_EXTERN(int) git_stash_save(
git_oid *out,
git_repository *repo,
git_signature *stasher,
const char *message,
uint32_t flags);
/**
* When iterating over all the stashed states, callback that will be
* issued per entry.
*
* @param index The position within the stash list. 0 points to the
* most recent stashed state.
*
* @param message The stash message.
*
* @param stash_oid The commit oid of the stashed state.
*
* @param payload Extra parameter to callback function.
*
* @return 0 on success, GIT_EUSER on non-zero callback, or error code
*/
typedef int (*stash_cb)(
size_t index,
const char* message,
const git_oid *stash_oid,
void *payload);
/**
* Loop over all the stashed states and issue a callback for each one.
*
* If the callback returns a non-zero value, this will stop looping.
*
* @param repo Repository where to find the stash.
*
* @param callabck Callback to invoke per found stashed state. The most recent
* stash state will be enumerated first.
*
* @param payload Extra parameter to callback function.
*
* @return 0 on success, GIT_EUSER on non-zero callback, or error code
*/
GIT_EXTERN(int) git_stash_foreach(
git_repository *repo,
stash_cb callback,
void *payload);
/**
* Remove a single stashed state from the stash list.
*
* @param repo The owning repository.
*
* @param index The position within the stash list. 0 points to the
* most recent stashed state.
*
* @return 0 on success, or error code
*/
GIT_EXTERN(int) git_stash_drop(
git_repository *repo,
size_t index);
/** @} */
GIT_END_DECL
#endif
......@@ -1071,3 +1071,8 @@ int git_index_read_tree(git_index *index, git_tree *tree)
return git_tree_walk(tree, read_tree_cb, GIT_TREEWALK_POST, index);
}
git_repository *git_index_owner(const git_index *index)
{
return INDEX_OWNER(index);
}
......@@ -166,6 +166,9 @@ void git_reflog_free(git_reflog *reflog)
unsigned int i;
git_reflog_entry *entry;
if (reflog == NULL)
return;
for (i=0; i < reflog->entries.length; i++) {
entry = git_vector_get(&reflog->entries, i);
......@@ -185,7 +188,10 @@ static int retrieve_reflog_path(git_buf *path, git_reference *ref)
static int create_new_reflog_file(const char *filepath)
{
int fd;
int fd, error;
if ((error = git_futils_mkpath2file(filepath, GIT_REFLOG_DIR_MODE)) < 0)
return error;
if ((fd = p_open(filepath,
O_WRONLY | O_CREAT | O_TRUNC,
......@@ -463,26 +469,26 @@ int git_reflog_drop(
if (!rewrite_previous_entry)
return 0;
/* No need to rewrite anything when removing the first entry */
if (idx == 0)
/* No need to rewrite anything when removing the most recent entry */
if (idx == entrycount - 1)
return 0;
/* There are no more entries in the log */
if (entrycount == 1)
return 0;
entry = (git_reflog_entry *)git_reflog_entry_byindex(reflog, idx - 1);
entry = (git_reflog_entry *)git_reflog_entry_byindex(reflog, idx);
/* If the last entry has just been removed... */
if (idx == entrycount - 1) {
/* ...clear the oid_old member of the "new" last entry */
/* If the oldest entry has just been removed... */
if (idx == 0) {
/* ...clear the oid_old member of the "new" oldest entry */
if (git_oid_fromstr(&entry->oid_old, GIT_OID_HEX_ZERO) < 0)
return -1;
return 0;
}
previous = (git_reflog_entry *)git_reflog_entry_byindex(reflog, idx);
previous = (git_reflog_entry *)git_reflog_entry_byindex(reflog, idx - 1);
git_oid_cpy(&entry->oid_old, &previous->oid_cur);
return 0;
......
......@@ -35,6 +35,9 @@
#define GIT_CHERRY_PICK_HEAD_FILE "CHERRY_PICK_HEAD"
#define GIT_REFS_HEADS_MASTER_FILE GIT_REFS_HEADS_DIR "master"
#define GIT_STASH_FILE "stash"
#define GIT_REFS_STASH_FILE GIT_REFS_DIR GIT_STASH_FILE
#define GIT_REFNAME_MAX 1024
struct git_reference {
......
This diff is collapsed. Click to expand it.
......@@ -128,68 +128,3 @@ void test_object_commit_commitstagedfile__generate_predictable_object_ids(void)
git_tree_free(tree);
git_index_free(index);
}
void test_object_commit_commitstagedfile__message_prettify(void)
{
char buffer[100];
cl_assert(git_message_prettify(buffer, sizeof(buffer), "", 0) == 1);
cl_assert_equal_s(buffer, "");
cl_assert(git_message_prettify(buffer, sizeof(buffer), "", 1) == 1);
cl_assert_equal_s(buffer, "");
cl_assert_equal_i(7, git_message_prettify(buffer, sizeof(buffer), "Short", 0));
cl_assert_equal_s("Short\n", buffer);
cl_assert_equal_i(7, git_message_prettify(buffer, sizeof(buffer), "Short", 1));
cl_assert_equal_s("Short\n", buffer);
cl_assert(git_message_prettify(buffer, sizeof(buffer), "This is longer\nAnd multiline\n# with some comments still in\n", 0) > 0);
cl_assert_equal_s(buffer, "This is longer\nAnd multiline\n# with some comments still in\n");
cl_assert(git_message_prettify(buffer, sizeof(buffer), "This is longer\nAnd multiline\n# with some comments still in\n", 1) > 0);
cl_assert_equal_s(buffer, "This is longer\nAnd multiline\n");
/* try out overflow */
cl_assert(git_message_prettify(buffer, sizeof(buffer),
"1234567890" "1234567890" "1234567890" "1234567890" "1234567890"
"1234567890" "1234567890" "1234567890" "1234567890" "12345678",
0) > 0);
cl_assert_equal_s(buffer,
"1234567890" "1234567890" "1234567890" "1234567890" "1234567890"
"1234567890" "1234567890" "1234567890" "1234567890" "12345678\n");
cl_assert(git_message_prettify(buffer, sizeof(buffer),
"1234567890" "1234567890" "1234567890" "1234567890" "1234567890"
"1234567890" "1234567890" "1234567890" "1234567890" "12345678\n",
0) > 0);
cl_assert_equal_s(buffer,
"1234567890" "1234567890" "1234567890" "1234567890" "1234567890"
"1234567890" "1234567890" "1234567890" "1234567890" "12345678\n");
cl_git_fail(git_message_prettify(buffer, sizeof(buffer),
"1234567890" "1234567890" "1234567890" "1234567890" "1234567890"
"1234567890" "1234567890" "1234567890" "1234567890" "123456789",
0));
cl_git_fail(git_message_prettify(buffer, sizeof(buffer),
"1234567890" "1234567890" "1234567890" "1234567890" "1234567890"
"1234567890" "1234567890" "1234567890" "1234567890" "123456789\n",
0));
cl_git_fail(git_message_prettify(buffer, sizeof(buffer),
"1234567890" "1234567890" "1234567890" "1234567890" "1234567890"
"1234567890" "1234567890" "1234567890" "1234567890" "1234567890",
0));
cl_git_fail(git_message_prettify(buffer, sizeof(buffer),
"1234567890" "1234567890" "1234567890" "1234567890" "1234567890"
"1234567890" "1234567890" "1234567890" "1234567890" "1234567890""x",
0));
cl_assert(git_message_prettify(buffer, sizeof(buffer),
"1234567890" "1234567890" "1234567890" "1234567890" "1234567890\n"
"# 1234567890" "1234567890" "1234567890" "1234567890" "1234567890\n"
"1234567890",
1) > 0);
cl_assert(git_message_prettify(NULL, 0, "", 0) == 1);
cl_assert(git_message_prettify(NULL, 0, "Short test", 0) == 12);
cl_assert(git_message_prettify(NULL, 0, "Test\n# with\nComments", 1) == 15);
}
......@@ -169,3 +169,68 @@ void test_object_message__keep_comments(void)
assert_message_prettifying("# comment\n" ttt "\n", "# comment\n" ttt "\n", 0);
assert_message_prettifying(ttt "\n" "# comment\n" ttt "\n", ttt "\n" "# comment\n" ttt "\n", 0);
}
void test_object_message__message_prettify(void)
{
char buffer[100];
cl_assert(git_message_prettify(buffer, sizeof(buffer), "", 0) == 1);
cl_assert_equal_s(buffer, "");
cl_assert(git_message_prettify(buffer, sizeof(buffer), "", 1) == 1);
cl_assert_equal_s(buffer, "");
cl_assert_equal_i(7, git_message_prettify(buffer, sizeof(buffer), "Short", 0));
cl_assert_equal_s("Short\n", buffer);
cl_assert_equal_i(7, git_message_prettify(buffer, sizeof(buffer), "Short", 1));
cl_assert_equal_s("Short\n", buffer);
cl_assert(git_message_prettify(buffer, sizeof(buffer), "This is longer\nAnd multiline\n# with some comments still in\n", 0) > 0);
cl_assert_equal_s(buffer, "This is longer\nAnd multiline\n# with some comments still in\n");
cl_assert(git_message_prettify(buffer, sizeof(buffer), "This is longer\nAnd multiline\n# with some comments still in\n", 1) > 0);
cl_assert_equal_s(buffer, "This is longer\nAnd multiline\n");
/* try out overflow */
cl_assert(git_message_prettify(buffer, sizeof(buffer),
"1234567890" "1234567890" "1234567890" "1234567890" "1234567890"
"1234567890" "1234567890" "1234567890" "1234567890" "12345678",
0) > 0);
cl_assert_equal_s(buffer,
"1234567890" "1234567890" "1234567890" "1234567890" "1234567890"
"1234567890" "1234567890" "1234567890" "1234567890" "12345678\n");
cl_assert(git_message_prettify(buffer, sizeof(buffer),
"1234567890" "1234567890" "1234567890" "1234567890" "1234567890"
"1234567890" "1234567890" "1234567890" "1234567890" "12345678\n",
0) > 0);
cl_assert_equal_s(buffer,
"1234567890" "1234567890" "1234567890" "1234567890" "1234567890"
"1234567890" "1234567890" "1234567890" "1234567890" "12345678\n");
cl_git_fail(git_message_prettify(buffer, sizeof(buffer),
"1234567890" "1234567890" "1234567890" "1234567890" "1234567890"
"1234567890" "1234567890" "1234567890" "1234567890" "123456789",
0));
cl_git_fail(git_message_prettify(buffer, sizeof(buffer),
"1234567890" "1234567890" "1234567890" "1234567890" "1234567890"
"1234567890" "1234567890" "1234567890" "1234567890" "123456789\n",
0));
cl_git_fail(git_message_prettify(buffer, sizeof(buffer),
"1234567890" "1234567890" "1234567890" "1234567890" "1234567890"
"1234567890" "1234567890" "1234567890" "1234567890" "1234567890",
0));
cl_git_fail(git_message_prettify(buffer, sizeof(buffer),
"1234567890" "1234567890" "1234567890" "1234567890" "1234567890"
"1234567890" "1234567890" "1234567890" "1234567890" "1234567890""x",
0));
cl_assert(git_message_prettify(buffer, sizeof(buffer),
"1234567890" "1234567890" "1234567890" "1234567890" "1234567890\n"
"# 1234567890" "1234567890" "1234567890" "1234567890" "1234567890\n"
"1234567890",
1) > 0);
cl_assert(git_message_prettify(NULL, 0, "", 0) == 1);
cl_assert(git_message_prettify(NULL, 0, "Short test", 0) == 12);
cl_assert(git_message_prettify(NULL, 0, "Test\n# with\nComments", 1) == 15);
}
......@@ -43,57 +43,48 @@ void test_refs_reflog_drop__can_drop_an_entry(void)
void test_refs_reflog_drop__can_drop_an_entry_and_rewrite_the_log_history(void)
{
const git_reflog_entry *before_previous, *before_next;
const git_reflog_entry *after_next;
git_oid before_next_old_oid;
const git_reflog_entry *before_current;
const git_reflog_entry *after_current;
git_oid before_current_old_oid, before_current_cur_oid;
cl_assert(entrycount > 4);
before_previous = git_reflog_entry_byindex(g_reflog, 3);
before_next = git_reflog_entry_byindex(g_reflog, 1);
git_oid_cpy(&before_next_old_oid, &before_next->oid_old);
before_current = git_reflog_entry_byindex(g_reflog, 2);
git_oid_cpy(&before_current_old_oid, &before_current->oid_old);
git_oid_cpy(&before_current_cur_oid, &before_current->oid_cur);
cl_git_pass(git_reflog_drop(g_reflog, 2, 1));
cl_assert_equal_i(entrycount - 1, git_reflog_entrycount(g_reflog));
after_next = git_reflog_entry_byindex(g_reflog, 1);
after_current = git_reflog_entry_byindex(g_reflog, 2);
cl_assert_equal_i(0, git_oid_cmp(&before_next->oid_cur, &after_next->oid_cur));
cl_assert(git_oid_cmp(&before_next_old_oid, &after_next->oid_old) != 0);
cl_assert_equal_i(0, git_oid_cmp(&before_previous->oid_cur, &after_next->oid_old));
cl_assert_equal_i(0, git_oid_cmp(&before_current_old_oid, &after_current->oid_old));
cl_assert(0 != git_oid_cmp(&before_current_cur_oid, &after_current->oid_cur));
}
void test_refs_reflog_drop__can_drop_the_first_entry(void)
{
cl_assert(entrycount > 2);
cl_git_pass(git_reflog_drop(g_reflog, 0, 0));
cl_assert_equal_i(entrycount - 1, git_reflog_entrycount(g_reflog));
}
void test_refs_reflog_drop__can_drop_the_last_entry(void)
void test_refs_reflog_drop__can_drop_the_oldest_entry(void)
{
const git_reflog_entry *entry;
cl_assert(entrycount > 2);
cl_git_pass(git_reflog_drop(g_reflog, entrycount - 1, 0));
cl_git_pass(git_reflog_drop(g_reflog, 0, 0));
cl_assert_equal_i(entrycount - 1, git_reflog_entrycount(g_reflog));
entry = git_reflog_entry_byindex(g_reflog, entrycount - 2);
entry = git_reflog_entry_byindex(g_reflog, 0);
cl_assert(git_oid_streq(&entry->oid_old, GIT_OID_HEX_ZERO) != 0);
}
void test_refs_reflog_drop__can_drop_the_last_entry_and_rewrite_the_log_history(void)
void test_refs_reflog_drop__can_drop_the_oldest_entry_and_rewrite_the_log_history(void)
{
const git_reflog_entry *entry;
cl_assert(entrycount > 2);
cl_git_pass(git_reflog_drop(g_reflog, entrycount - 1, 1));
cl_git_pass(git_reflog_drop(g_reflog, 0, 1));
cl_assert_equal_i(entrycount - 1, git_reflog_entrycount(g_reflog));
entry = git_reflog_entry_byindex(g_reflog, entrycount - 2);
entry = git_reflog_entry_byindex(g_reflog, 0);
cl_assert(git_oid_streq(&entry->oid_old, GIT_OID_HEX_ZERO) == 0);
}
......
#include "clar_libgit2.h"
#include "fileops.h"
#include "stash_helpers.h"
static git_repository *repo;
static git_signature *signature;
void test_stash_drop__initialize(void)
{
cl_git_pass(git_repository_init(&repo, "stash", 0));
cl_git_pass(git_signature_new(&signature, "nulltoken", "emeric.fermas@gmail.com", 1323847743, 60)); /* Wed Dec 14 08:29:03 2011 +0100 */
}
void test_stash_drop__cleanup(void)
{
git_signature_free(signature);
git_repository_free(repo);
cl_git_pass(git_futils_rmdir_r("stash", NULL, GIT_DIRREMOVAL_FILES_AND_DIRS));
}
void test_stash_drop__cannot_drop_from_an_empty_stash(void)
{
cl_assert_equal_i(GIT_ENOTFOUND, git_stash_drop(repo, 0));
}
static void push_three_states(void)
{
git_oid oid;
git_index *index;
cl_git_mkfile("stash/zero.txt", "content\n");
cl_git_pass(git_repository_index(&index, repo));
cl_git_pass(git_index_add(index, "zero.txt", 0));
commit_staged_files(&oid, index, signature);
cl_git_mkfile("stash/one.txt", "content\n");
cl_git_pass(git_stash_save(&oid, repo, signature, "First", GIT_STASH_INCLUDE_UNTRACKED));
cl_git_mkfile("stash/two.txt", "content\n");
cl_git_pass(git_stash_save(&oid, repo, signature, "Second", GIT_STASH_INCLUDE_UNTRACKED));
cl_git_mkfile("stash/three.txt", "content\n");
cl_git_pass(git_stash_save(&oid, repo, signature, "Third", GIT_STASH_INCLUDE_UNTRACKED));
git_index_free(index);
}
void test_stash_drop__cannot_drop_a_non_existing_stashed_state(void)
{
push_three_states();
cl_assert_equal_i(GIT_ENOTFOUND, git_stash_drop(repo, 666));
cl_assert_equal_i(GIT_ENOTFOUND, git_stash_drop(repo, 42));
cl_assert_equal_i(GIT_ENOTFOUND, git_stash_drop(repo, 3));
}
void test_stash_drop__can_purge_the_stash_from_the_top(void)
{
push_three_states();
cl_git_pass(git_stash_drop(repo, 0));
cl_git_pass(git_stash_drop(repo, 0));
cl_git_pass(git_stash_drop(repo, 0));
cl_assert_equal_i(GIT_ENOTFOUND, git_stash_drop(repo, 0));
}
void test_stash_drop__can_purge_the_stash_from_the_bottom(void)
{
push_three_states();
cl_git_pass(git_stash_drop(repo, 2));
cl_git_pass(git_stash_drop(repo, 1));
cl_git_pass(git_stash_drop(repo, 0));
cl_assert_equal_i(GIT_ENOTFOUND, git_stash_drop(repo, 0));
}
void test_stash_drop__dropping_an_entry_rewrites_reflog_history(void)
{
git_reference *stash;
git_reflog *reflog;
const git_reflog_entry *entry;
git_oid oid;
size_t count;
push_three_states();
cl_git_pass(git_reference_lookup(&stash, repo, "refs/stash"));
cl_git_pass(git_reflog_read(&reflog, stash));
entry = git_reflog_entry_byindex(reflog, 1);
git_oid_cpy(&oid, git_reflog_entry_oidold(entry));
count = git_reflog_entrycount(reflog);
git_reflog_free(reflog);
cl_git_pass(git_stash_drop(repo, 1));
cl_git_pass(git_reflog_read(&reflog, stash));
entry = git_reflog_entry_byindex(reflog, 1);
cl_assert_equal_i(0, git_oid_cmp(&oid, git_reflog_entry_oidold(entry)));
cl_assert_equal_i(count - 1, git_reflog_entrycount(reflog));
git_reflog_free(reflog);
git_reference_free(stash);
}
void test_stash_drop__dropping_the_last_entry_removes_the_stash(void)
{
git_reference *stash;
push_three_states();
cl_git_pass(git_reference_lookup(&stash, repo, "refs/stash"));
git_reference_free(stash);
cl_git_pass(git_stash_drop(repo, 0));
cl_git_pass(git_stash_drop(repo, 0));
cl_git_pass(git_stash_drop(repo, 0));
cl_assert_equal_i(GIT_ENOTFOUND, git_reference_lookup(&stash, repo, "refs/stash"));
}
#include "clar_libgit2.h"
#include "fileops.h"
#include "stash_helpers.h"
struct callback_data
{
char **oids;
int invokes;
};
static git_repository *repo;
static git_signature *signature;
static git_oid stash_tip_oid;
struct callback_data data;
#define REPO_NAME "stash"
void test_stash_foreach__initialize(void)
{
cl_git_pass(git_signature_new(
&signature,
"nulltoken",
"emeric.fermas@gmail.com",
1323847743, 60)); /* Wed Dec 14 08:29:03 2011 +0100 */
memset(&data, 0, sizeof(struct callback_data));
}
void test_stash_foreach__cleanup(void)
{
git_signature_free(signature);
git_repository_free(repo);
cl_git_pass(git_futils_rmdir_r(REPO_NAME, NULL, GIT_DIRREMOVAL_FILES_AND_DIRS));
}
static int callback_cb(
size_t index,
const char* message,
const git_oid *stash_oid,
void *payload)
{
int i = 0;
bool found = false;
struct callback_data *data = (struct callback_data *)payload;
cl_assert_equal_i(0, git_oid_streq(stash_oid, data->oids[data->invokes++]));
return 0;
}
void test_stash_foreach__enumerating_a_empty_repository_doesnt_fail(void)
{
char *oids[] = { NULL };
data.oids = oids;
cl_git_pass(git_repository_init(&repo, REPO_NAME, 0));
cl_git_pass(git_stash_foreach(repo, callback_cb, &data));
cl_assert_equal_i(0, data.invokes);
}
void test_stash_foreach__can_enumerate_a_repository(void)
{
char *oids_default[] = {
"1d91c842a7cdfc25872b3a763e5c31add8816c25", NULL };
char *oids_untracked[] = {
"7f89a8b15c878809c5c54d1ff8f8c9674154017b",
"1d91c842a7cdfc25872b3a763e5c31add8816c25", NULL };
char *oids_ignored[] = {
"c95599a8fef20a7e57582c6727b1a0d02e0a5828",
"7f89a8b15c878809c5c54d1ff8f8c9674154017b",
"1d91c842a7cdfc25872b3a763e5c31add8816c25", NULL };
cl_git_pass(git_repository_init(&repo, REPO_NAME, 0));
setup_stash(repo, signature);
cl_git_pass(git_stash_save(
&stash_tip_oid,
repo,
signature,
NULL,
GIT_STASH_DEFAULT));
data.oids = oids_default;
cl_git_pass(git_stash_foreach(repo, callback_cb, &data));
cl_assert_equal_i(1, data.invokes);
data.oids = oids_untracked;
data.invokes = 0;
cl_git_pass(git_stash_save(
&stash_tip_oid,
repo,
signature,
NULL,
GIT_STASH_INCLUDE_UNTRACKED));
cl_git_pass(git_stash_foreach(repo, callback_cb, &data));
cl_assert_equal_i(2, data.invokes);
data.oids = oids_ignored;
data.invokes = 0;
cl_git_pass(git_stash_save(
&stash_tip_oid,
repo,
signature,
NULL,
GIT_STASH_INCLUDE_IGNORED));
cl_git_pass(git_stash_foreach(repo, callback_cb, &data));
cl_assert_equal_i(3, data.invokes);
}
#include "clar_libgit2.h"
#include "fileops.h"
void commit_staged_files(
git_oid *commit_oid,
git_index *index,
git_signature *signature)
{
git_tree *tree;
git_oid tree_oid;
git_repository *repo;
repo = git_index_owner(index);
cl_git_pass(git_tree_create_fromindex(&tree_oid, index));
cl_git_pass(git_tree_lookup(&tree, repo, &tree_oid));
cl_git_pass(git_commit_create_v(
commit_oid,
repo,
"HEAD",
signature,
signature,
NULL,
"Initial commit",
tree,
0));
git_tree_free(tree);
}
void setup_stash(git_repository *repo, git_signature *signature)
{
git_oid commit_oid;
git_index *index;
cl_git_pass(git_repository_index(&index, repo));
cl_git_mkfile("stash/what", "hello\n"); /* ce013625030ba8dba906f756967f9e9ca394464a */
cl_git_mkfile("stash/how", "small\n"); /* ac790413e2d7a26c3767e78c57bb28716686eebc */
cl_git_mkfile("stash/who", "world\n"); /* cc628ccd10742baea8241c5924df992b5c019f71 */
cl_git_mkfile("stash/when", "now\n"); /* b6ed15e81e2593d7bb6265eb4a991d29dc3e628b */
cl_git_mkfile("stash/just.ignore", "me\n"); /* 78925fb1236b98b37a35e9723033e627f97aa88b */
cl_git_mkfile("stash/.gitignore", "*.ignore\n");
cl_git_pass(git_index_add(index, "what", 0));
cl_git_pass(git_index_add(index, "how", 0));
cl_git_pass(git_index_add(index, "who", 0));
cl_git_pass(git_index_add(index, ".gitignore", 0));
cl_git_pass(git_index_write(index));
commit_staged_files(&commit_oid, index, signature);
cl_git_rewritefile("stash/what", "goodbye\n"); /* dd7e1c6f0fefe118f0b63d9f10908c460aa317a6 */
cl_git_rewritefile("stash/how", "not so small and\n"); /* e6d64adb2c7f3eb8feb493b556cc8070dca379a3 */
cl_git_rewritefile("stash/who", "funky world\n"); /* a0400d4954659306a976567af43125a0b1aa8595 */
cl_git_pass(git_index_add(index, "what", 0));
cl_git_pass(git_index_add(index, "how", 0));
cl_git_pass(git_index_write(index));
cl_git_rewritefile("stash/what", "see you later\n"); /* bc99dc98b3eba0e9157e94769cd4d49cb49de449 */
git_index_free(index);
}
void setup_stash(
git_repository *repo,
git_signature *signature);
void commit_staged_files(
git_oid *commit_oid,
git_index *index,
git_signature *signature);
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment