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
0b98a8a4
Commit
0b98a8a4
authored
Sep 07, 2012
by
nulltoken
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
branch: remove config section upon deletion
parent
5edb846e
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
91 additions
and
0 deletions
+91
-0
src/branch.c
+49
-0
tests-clar/config/config_helpers.c
+22
-0
tests-clar/config/config_helpers.h
+4
-0
tests-clar/refs/branches/delete.c
+16
-0
No files found.
src/branch.c
View file @
0b98a8a4
...
@@ -89,6 +89,50 @@ cleanup:
...
@@ -89,6 +89,50 @@ cleanup:
return
error
;
return
error
;
}
}
static
int
delete_config_entries_cb
(
const
char
*
var_name
,
const
char
*
value
,
void
*
payload
)
{
git_config
*
config
;
GIT_UNUSED
(
value
);
config
=
(
git_config
*
)
payload
;
return
git_config_delete
(
config
,
var_name
);
}
static
int
delete_branch_config_entries
(
git_repository
*
repo
,
const
char
*
branch_name
)
{
git_config
*
config
;
git_buf
pattern
=
GIT_BUF_INIT
;
int
error
=
-
1
;
git_buf_sets
(
&
pattern
,
"branch
\\
."
);
git_buf_puts_escape_regex
(
&
pattern
,
branch_name
);
git_buf_puts
(
&
pattern
,
"
\\
..+"
);
if
(
git_buf_oom
(
&
pattern
))
goto
cleanup
;
if
(
git_repository_config__weakptr
(
&
config
,
repo
)
<
0
)
goto
cleanup
;
if
((
error
=
git_config_foreach_match
(
config
,
git_buf_cstr
(
&
pattern
),
delete_config_entries_cb
,
config
))
<
0
)
goto
cleanup
;
error
=
0
;
cleanup:
git_buf_free
(
&
pattern
);
return
error
;
}
int
git_branch_delete
(
git_reference
*
branch
)
int
git_branch_delete
(
git_reference
*
branch
)
{
{
int
is_head
;
int
is_head
;
...
@@ -110,6 +154,11 @@ int git_branch_delete(git_reference *branch)
...
@@ -110,6 +154,11 @@ int git_branch_delete(git_reference *branch)
return
-
1
;
return
-
1
;
}
}
if
(
delete_branch_config_entries
(
git_reference_owner
(
branch
),
git_reference_name
(
branch
)
+
strlen
(
GIT_REFS_HEADS_DIR
))
<
0
)
goto
on_error
;
return
git_reference_delete
(
branch
);
return
git_reference_delete
(
branch
);
}
}
...
...
tests-clar/config/config_helpers.c
0 → 100644
View file @
0b98a8a4
#include "clar_libgit2.h"
#include "config_helpers.h"
#include "repository.h"
void
assert_config_entry_existence
(
git_repository
*
repo
,
const
char
*
name
,
bool
is_supposed_to_exist
)
{
git_config
*
config
;
const
char
*
out
;
int
result
;
cl_git_pass
(
git_repository_config__weakptr
(
&
config
,
repo
));
result
=
git_config_get_string
(
&
out
,
config
,
name
);
if
(
is_supposed_to_exist
)
cl_git_pass
(
result
);
else
cl_assert_equal_i
(
GIT_ENOTFOUND
,
result
);
}
tests-clar/config/config_helpers.h
0 → 100644
View file @
0b98a8a4
extern
void
assert_config_entry_existence
(
git_repository
*
repo
,
const
char
*
name
,
bool
is_supposed_to_exist
);
tests-clar/refs/branches/delete.c
View file @
0b98a8a4
#include "clar_libgit2.h"
#include "clar_libgit2.h"
#include "refs.h"
#include "refs.h"
#include "repo/repo_helpers.h"
#include "repo/repo_helpers.h"
#include "config/config_helpers.h"
static
git_repository
*
repo
;
static
git_repository
*
repo
;
static
git_reference
*
fake_remote
;
static
git_reference
*
fake_remote
;
...
@@ -90,3 +91,17 @@ void test_refs_branches_delete__can_delete_a_remote_branch(void)
...
@@ -90,3 +91,17 @@ void test_refs_branches_delete__can_delete_a_remote_branch(void)
cl_git_pass
(
git_branch_lookup
(
&
branch
,
repo
,
"nulltoken/master"
,
GIT_BRANCH_REMOTE
));
cl_git_pass
(
git_branch_lookup
(
&
branch
,
repo
,
"nulltoken/master"
,
GIT_BRANCH_REMOTE
));
cl_git_pass
(
git_branch_delete
(
branch
));
cl_git_pass
(
git_branch_delete
(
branch
));
}
}
void
test_refs_branches_delete__deleting_a_branch_removes_related_configuration_data
(
void
)
{
git_reference
*
branch
;
assert_config_entry_existence
(
repo
,
"branch.track-local.remote"
,
true
);
assert_config_entry_existence
(
repo
,
"branch.track-local.merge"
,
true
);
cl_git_pass
(
git_branch_lookup
(
&
branch
,
repo
,
"track-local"
,
GIT_BRANCH_LOCAL
));
cl_git_pass
(
git_branch_delete
(
branch
));
assert_config_entry_existence
(
repo
,
"branch.track-local.remote"
,
false
);
assert_config_entry_existence
(
repo
,
"branch.track-local.merge"
,
false
);
}
\ No newline at end of file
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