diff options
author | Russell Belfer <rb@github.com> | 2012-09-17 11:38:33 -0700 |
---|---|---|
committer | Russell Belfer <rb@github.com> | 2012-09-17 11:38:33 -0700 |
commit | 411cb017c21e0490ed1c6438c7d5fa1b4ee9f63f (patch) | |
tree | b7186ea6d0cf23326d18f26c090e07d084f3f911 /include/git2 | |
parent | e8776d30f7edb570f435cf746d712c696b862bdd (diff) | |
parent | 397837197d1ce04b8bd4aaa57a7f5f67648dc57f (diff) | |
download | libgit2-411cb017c21e0490ed1c6438c7d5fa1b4ee9f63f.tar.gz |
Merge pull request #887 from nulltoken/topic/reset-hard
Checkout, reset and others enhancements
Diffstat (limited to 'include/git2')
-rw-r--r-- | include/git2/checkout.h | 44 | ||||
-rw-r--r-- | include/git2/repository.h | 63 | ||||
-rw-r--r-- | include/git2/reset.h | 3 | ||||
-rw-r--r-- | include/git2/types.h | 1 |
4 files changed, 101 insertions, 10 deletions
diff --git a/include/git2/checkout.h b/include/git2/checkout.h index deb828722..42d47003d 100644 --- a/include/git2/checkout.h +++ b/include/git2/checkout.h @@ -21,21 +21,30 @@ */ GIT_BEGIN_DECL - -#define GIT_CHECKOUT_OVERWRITE_EXISTING 0 /* default */ -#define GIT_CHECKOUT_SKIP_EXISTING 1 +enum { + GIT_CHECKOUT_DEFAULT = (1 << 0), + GIT_CHECKOUT_OVERWRITE_MODIFIED = (1 << 1), + GIT_CHECKOUT_CREATE_MISSING = (1 << 2), + GIT_CHECKOUT_REMOVE_UNTRACKED = (1 << 3), +}; /* Use zeros to indicate default settings */ typedef struct git_checkout_opts { - int existing_file_action; /* default: GIT_CHECKOUT_OVERWRITE_EXISTING */ + unsigned int checkout_strategy; /* default: GIT_CHECKOUT_DEFAULT */ int disable_filters; int dir_mode; /* default is 0755 */ int file_mode; /* default is 0644 */ int file_open_flags; /* default is O_CREAT | O_TRUNC | O_WRONLY */ + + /* when not NULL, arrays of fnmatch pattern specifying + * which paths should be taken into account + */ + git_strarray paths; } git_checkout_opts; /** - * Updates files in the working tree to match the commit pointed to by HEAD. + * Updates files in the index and the working tree to match the content of the + * commit pointed at by HEAD. * * @param repo repository to check out (must be non-bare) * @param opts specifies checkout options (may be NULL) @@ -49,19 +58,36 @@ GIT_EXTERN(int) git_checkout_head( git_indexer_stats *stats); /** - * Updates files in the working tree to match a commit pointed to by a ref. + * Updates files in the working tree to match the content of the index. * - * @param ref reference to follow to a commit + * @param repo repository to check out (must be non-bare) * @param opts specifies checkout options (may be NULL) * @param stats structure through which progress information is reported * @return 0 on success, GIT_ERROR otherwise (use giterr_last for information * about the error) */ -GIT_EXTERN(int) git_checkout_reference( - git_reference *ref, +GIT_EXTERN(int) git_checkout_index( + git_repository *repo, git_checkout_opts *opts, git_indexer_stats *stats); +/** + * Updates files in the index and working tree to match the content of the + * tree pointed at by the treeish. + * + * @param repo repository to check out (must be non-bare) + * @param treeish a commit, tag or tree which content will be used to update + * the working directory + * @param opts specifies checkout options (may be NULL) + * @param stats structure through which progress information is reported + * @return 0 on success, GIT_ERROR otherwise (use giterr_last for information + * about the error) + */ +GIT_EXTERN(int) git_checkout_tree( + git_repository *repo, + git_object *treeish, + git_checkout_opts *opts, + git_indexer_stats *stats); /** @} */ GIT_END_DECL diff --git a/include/git2/repository.h b/include/git2/repository.h index 32ec58dae..025a0a95d 100644 --- a/include/git2/repository.h +++ b/include/git2/repository.h @@ -456,7 +456,7 @@ GIT_EXTERN(int) git_repository_index(git_index **out, git_repository *repo); GIT_EXTERN(void) git_repository_set_index(git_repository *repo, git_index *index); /** - * Retrive git's prepared message + * Retrieve git's prepared message * * Operations such as git revert/cherry-pick/merge with the -n option * stop just short of creating a commit with the changes and save @@ -506,6 +506,67 @@ GIT_EXTERN(int) git_repository_hashfile( git_otype type, const char *as_path); +/** + * Make the repository HEAD point to the specified reference. + * + * If the provided reference points to a Tree or a Blob, the HEAD is + * unaltered and -1 is returned. + * + * If the provided reference points to a branch, the HEAD will point + * to that branch, staying attached, or become attached if it isn't yet. + * If the branch doesn't exist yet, no error will be return. The HEAD + * will then be attached to an unborn branch. + * + * Otherwise, the HEAD will be detached and will directly point to + * the Commit. + * + * @param repo Repository pointer + * @param refname Canonical name of the reference the HEAD should point at + * @return 0 on success, or an error code + */ +GIT_EXTERN(int) git_repository_set_head( + git_repository* repo, + const char* refname); + +/** + * Make the repository HEAD directly point to the Commit. + * + * If the provided committish cannot be found in the repository, the HEAD + * is unaltered and GIT_ENOTFOUND is returned. + * + * If the provided commitish cannot be peeled into a commit, the HEAD + * is unaltered and -1 is returned. + * + * Otherwise, the HEAD will eventually be detached and will directly point to + * the peeled Commit. + * + * @param repo Repository pointer + * @param commitish Object id of the Commit the HEAD should point to + * @return 0 on success, or an error code + */ +GIT_EXTERN(int) git_repository_set_head_detached( + git_repository* repo, + const git_oid* commitish); + +/** + * Detach the HEAD. + * + * If the HEAD is already detached and points to a Commit, 0 is returned. + * + * If the HEAD is already detached and points to a Tag, the HEAD is + * updated into making it point to the peeled Commit, and 0 is returned. + * + * If the HEAD is already detached and points to a non commitish, the HEAD is + * unaletered, and -1 is returned. + * + * Otherwise, the HEAD will be detached and point to the peeled Commit. + * + * @param repo Repository pointer + * @return 0 on success, or an error code + */ +GIT_EXTERN(int) git_repository_detach_head( + git_repository* repo); + /** @} */ GIT_END_DECL #endif diff --git a/include/git2/reset.h b/include/git2/reset.h index cd263fa99..cdcfb7671 100644 --- a/include/git2/reset.h +++ b/include/git2/reset.h @@ -24,6 +24,9 @@ GIT_BEGIN_DECL * Specifying a Mixed kind of reset will trigger a Soft reset and the index will * be replaced with the content of the commit tree. * + * Specifying a Hard kind of reset will trigger a Mixed reset and the working + * directory will be replaced with the content of the index. + * * TODO: Implement remaining kinds of resets. * * @param repo Repository where to perform the reset operation. diff --git a/include/git2/types.h b/include/git2/types.h index d3a905372..26e9c57e7 100644 --- a/include/git2/types.h +++ b/include/git2/types.h @@ -173,6 +173,7 @@ typedef enum { typedef enum { GIT_RESET_SOFT = 1, GIT_RESET_MIXED = 2, + GIT_RESET_HARD = 3, } git_reset_type; /** Valid modes for index and tree entries. */ |