Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
e4c64cf2
Commit
e4c64cf2
authored
Oct 08, 2012
by
nulltoken
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
stash: add git_stash_drop()
parent
23388413
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
182 additions
and
1 deletions
+182
-1
include/git2/stash.h
+15
-0
src/reflog.c
+1
-1
src/stash.c
+40
-0
tests-clar/stash/drop.c
+126
-0
No files found.
include/git2/stash.h
View file @
e4c64cf2
...
...
@@ -102,6 +102,21 @@ GIT_EXTERN(int) git_stash_foreach(
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
src/reflog.c
View file @
e4c64cf2
...
...
@@ -481,7 +481,7 @@ int git_reflog_drop(
/* If the oldest entry has just been removed... */
if
(
idx
==
0
)
{
/* ...clear the oid_old member of the "new"
la
st entry */
/* ...clear the oid_old member of the "new"
olde
st entry */
if
(
git_oid_fromstr
(
&
entry
->
oid_old
,
GIT_OID_HEX_ZERO
)
<
0
)
return
-
1
;
...
...
src/stash.c
View file @
e4c64cf2
...
...
@@ -617,3 +617,43 @@ cleanup:
git_reflog_free
(
reflog
);
return
error
;
}
int
git_stash_drop
(
git_repository
*
repo
,
size_t
index
)
{
git_reference
*
stash
;
git_reflog
*
reflog
=
NULL
;
size_t
max
;
int
error
;
if
((
error
=
git_reference_lookup
(
&
stash
,
repo
,
GIT_REFS_STASH_FILE
))
<
0
)
return
error
;
if
((
error
=
git_reflog_read
(
&
reflog
,
stash
))
<
0
)
goto
cleanup
;
max
=
git_reflog_entrycount
(
reflog
);
if
(
index
>
max
-
1
)
{
error
=
GIT_ENOTFOUND
;
giterr_set
(
GITERR_STASH
,
"No stashed state at position %"
PRIuZ
,
index
);
goto
cleanup
;
}
if
((
error
=
git_reflog_drop
(
reflog
,
max
-
index
-
1
,
true
))
<
0
)
goto
cleanup
;
if
((
error
=
git_reflog_write
(
reflog
))
<
0
)
goto
cleanup
;
if
(
max
==
1
)
{
error
=
git_reference_delete
(
stash
);
stash
=
NULL
;
}
cleanup:
git_reference_free
(
stash
);
git_reflog_free
(
reflog
);
return
error
;
}
tests-clar/stash/drop.c
0 → 100644
View file @
e4c64cf2
#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"
));
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment