Commit 590fb68b by nulltoken

stash: add git_stash_save()

parent eb44cfe0
......@@ -52,5 +52,6 @@
#include "git2/reset.h"
#include "git2/message.h"
#include "git2/pack.h"
#include "git2/stash.h"
#endif
/*
* 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);
/** @} */
GIT_END_DECL
#endif
This diff is collapsed. Click to expand it.
#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