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
698bf1da
Commit
698bf1da
authored
Feb 22, 2013
by
Vicent Martí
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1354 from nulltoken/fix/stash-drop
Fix git_stash_drop()
parents
0309e850
9ccab8df
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
82 additions
and
9 deletions
+82
-9
src/stash.c
+6
-0
tests-clar/attr/ignore.c
+32
-0
tests-clar/stash/drop.c
+44
-9
No files found.
src/stash.c
View file @
698bf1da
...
...
@@ -646,6 +646,12 @@ int git_stash_drop(
if
(
max
==
1
)
{
error
=
git_reference_delete
(
stash
);
stash
=
NULL
;
}
else
if
(
index
==
0
)
{
const
git_reflog_entry
*
entry
;
entry
=
git_reflog_entry_byindex
(
reflog
,
0
);
error
=
git_reference_set_target
(
stash
,
&
entry
->
oid_cur
);
}
cleanup:
...
...
tests-clar/attr/ignore.c
0 → 100644
View file @
698bf1da
#include "clar_libgit2.h"
static
git_repository
*
g_repo
=
NULL
;
void
test_attr_ignore__initialize
(
void
)
{
g_repo
=
cl_git_sandbox_init
(
"attr"
);
}
void
test_attr_ignore__cleanup
(
void
)
{
cl_git_sandbox_cleanup
();
g_repo
=
NULL
;
}
void
assert_is_ignored
(
bool
expected
,
const
char
*
filepath
)
{
int
is_ignored
;
cl_git_pass
(
git_ignore_path_is_ignored
(
&
is_ignored
,
g_repo
,
filepath
));
cl_assert_equal_i
(
expected
,
is_ignored
==
1
);
}
void
test_attr_ignore__honor_temporary_rules
(
void
)
{
cl_git_rewritefile
(
"attr/.gitignore"
,
"/NewFolder
\n
/NewFolder/NewFolder"
);
assert_is_ignored
(
false
,
"File.txt"
);
assert_is_ignored
(
true
,
"NewFolder"
);
assert_is_ignored
(
true
,
"NewFolder/NewFolder"
);
assert_is_ignored
(
true
,
"NewFolder/NewFolder/File.txt"
);
}
tests-clar/stash/drop.c
View file @
698bf1da
#include "clar_libgit2.h"
#include "fileops.h"
#include "stash_helpers.h"
#include "refs.h"
static
git_repository
*
repo
;
static
git_signature
*
signature
;
...
...
@@ -24,7 +25,7 @@ void test_stash_drop__cleanup(void)
void
test_stash_drop__cannot_drop_from_an_empty_stash
(
void
)
{
cl_
assert_equal_i
(
GIT_ENOTFOUND
,
git_stash_drop
(
repo
,
0
)
);
cl_
git_fail_with
(
git_stash_drop
(
repo
,
0
),
GIT_ENOTFOUND
);
}
static
void
push_three_states
(
void
)
...
...
@@ -60,9 +61,9 @@ 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
)
);
cl_
git_fail_with
(
git_stash_drop
(
repo
,
666
),
GIT_ENOTFOUND
);
cl_
git_fail_with
(
git_stash_drop
(
repo
,
42
),
GIT_ENOTFOUND
);
cl_
git_fail_with
(
git_stash_drop
(
repo
,
3
),
GIT_ENOTFOUND
);
}
void
test_stash_drop__can_purge_the_stash_from_the_top
(
void
)
...
...
@@ -73,7 +74,7 @@ void test_stash_drop__can_purge_the_stash_from_the_top(void)
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
)
);
cl_
git_fail_with
(
git_stash_drop
(
repo
,
0
),
GIT_ENOTFOUND
);
}
void
test_stash_drop__can_purge_the_stash_from_the_bottom
(
void
)
...
...
@@ -84,7 +85,7 @@ void test_stash_drop__can_purge_the_stash_from_the_bottom(void)
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
)
);
cl_
git_fail_with
(
git_stash_drop
(
repo
,
0
),
GIT_ENOTFOUND
);
}
void
test_stash_drop__dropping_an_entry_rewrites_reflog_history
(
void
)
...
...
@@ -97,7 +98,7 @@ void test_stash_drop__dropping_an_entry_rewrites_reflog_history(void)
push_three_states
();
cl_git_pass
(
git_reference_lookup
(
&
stash
,
repo
,
"refs/stash"
));
cl_git_pass
(
git_reference_lookup
(
&
stash
,
repo
,
GIT_REFS_STASH_FILE
));
cl_git_pass
(
git_reflog_read
(
&
reflog
,
stash
));
entry
=
git_reflog_entry_byindex
(
reflog
,
1
);
...
...
@@ -126,12 +127,46 @@ void test_stash_drop__dropping_the_last_entry_removes_the_stash(void)
push_three_states
();
cl_git_pass
(
git_reference_lookup
(
&
stash
,
repo
,
"refs/stash"
));
cl_git_pass
(
git_reference_lookup
(
&
stash
,
repo
,
GIT_REFS_STASH_FILE
));
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"
));
cl_git_fail_with
(
git_reference_lookup
(
&
stash
,
repo
,
GIT_REFS_STASH_FILE
),
GIT_ENOTFOUND
);
}
void
retrieve_top_stash_id
(
git_oid
*
out
)
{
git_object
*
top_stash
;
cl_git_pass
(
git_revparse_single
(
&
top_stash
,
repo
,
"stash@{0}"
));
cl_git_pass
(
git_reference_name_to_id
(
out
,
repo
,
GIT_REFS_STASH_FILE
));
cl_assert_equal_i
(
true
,
git_oid_cmp
(
out
,
git_object_id
(
top_stash
))
==
0
);
git_object_free
(
top_stash
);
}
void
test_stash_drop__dropping_the_top_stash_updates_the_stash_reference
(
void
)
{
git_object
*
next_top_stash
;
git_oid
oid
;
push_three_states
();
retrieve_top_stash_id
(
&
oid
);
cl_git_pass
(
git_revparse_single
(
&
next_top_stash
,
repo
,
"stash@{1}"
));
cl_assert_equal_i
(
false
,
git_oid_cmp
(
&
oid
,
git_object_id
(
next_top_stash
))
==
0
);
cl_git_pass
(
git_stash_drop
(
repo
,
0
));
retrieve_top_stash_id
(
&
oid
);
cl_assert_equal_i
(
true
,
git_oid_cmp
(
&
oid
,
git_object_id
(
next_top_stash
))
==
0
);
}
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