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
8462f7f9
Unverified
Commit
8462f7f9
authored
Jan 07, 2021
by
Edward Thomson
Committed by
GitHub
Jan 07, 2021
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5770 from libgit2/ethomson/empty_default_branch
Cope with empty default branch
parents
ba6824db
3f4bc213
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
57 additions
and
1 deletions
+57
-1
src/remote.c
+10
-0
src/repository.c
+2
-1
tests/fetchhead/nonetwork.c
+29
-0
tests/repo/init.c
+16
-0
No files found.
src/remote.c
View file @
8462f7f9
...
...
@@ -1141,6 +1141,16 @@ static int remote_head_for_ref(git_remote_head **out, git_remote *remote, git_re
ref_name
=
git_reference_name
(
resolved_ref
);
}
/*
* The ref name may be unresolvable - perhaps it's pointing to
* something invalid. In this case, there is no remote head for
* this ref.
*/
if
(
!
ref_name
)
{
error
=
0
;
goto
cleanup
;
}
if
((
error
=
ref_to_update
(
&
update
,
&
remote_name
,
remote
,
spec
,
ref_name
))
<
0
)
goto
cleanup
;
...
...
src/repository.c
View file @
8462f7f9
...
...
@@ -2092,7 +2092,8 @@ static int repo_init_head(const char *repo_dir, const char *given)
if
(
given
)
{
initial_head
=
given
;
}
else
if
((
error
=
git_config_open_default
(
&
cfg
))
>=
0
&&
(
error
=
git_config_get_string_buf
(
&
cfg_branch
,
cfg
,
"init.defaultbranch"
))
>=
0
)
{
(
error
=
git_config_get_string_buf
(
&
cfg_branch
,
cfg
,
"init.defaultbranch"
))
>=
0
&&
*
cfg_branch
.
ptr
)
{
initial_head
=
cfg_branch
.
ptr
;
}
...
...
tests/fetchhead/nonetwork.c
View file @
8462f7f9
...
...
@@ -319,6 +319,16 @@ static int assert_master_for_merge(const char *ref, const char *url, const git_o
return
0
;
}
static
int
assert_none_for_merge
(
const
char
*
ref
,
const
char
*
url
,
const
git_oid
*
id
,
unsigned
int
is_merge
,
void
*
data
)
{
GIT_UNUSED
(
ref
);
GIT_UNUSED
(
url
);
GIT_UNUSED
(
id
);
GIT_UNUSED
(
data
);
return
is_merge
?
-
1
:
0
;
}
void
test_fetchhead_nonetwork__unborn_with_upstream
(
void
)
{
git_repository
*
repo
;
...
...
@@ -366,6 +376,25 @@ void test_fetchhead_nonetwork__fetch_into_repo_with_symrefs(void)
cl_git_sandbox_cleanup
();
}
void
test_fetchhead_nonetwork__fetch_into_repo_with_invalid_head
(
void
)
{
git_remote
*
remote
;
char
*
strings
[]
=
{
"refs/heads/*:refs/remotes/origin/*"
};
git_strarray
refspecs
=
{
strings
,
1
};
cl_set_cleanup
(
&
cleanup_repository
,
"./test1"
);
cl_git_pass
(
git_repository_init
(
&
g_repo
,
"./test1"
,
0
));
/* HEAD pointing to nonexistent branch */
cl_git_rewritefile
(
"./test1/.git/HEAD"
,
"ref: refs/heads/
\n
"
);
cl_git_pass
(
git_remote_create_anonymous
(
&
remote
,
g_repo
,
cl_fixture
(
"testrepo.git"
)));
cl_git_pass
(
git_remote_fetch
(
remote
,
&
refspecs
,
NULL
,
NULL
));
cl_git_pass
(
git_repository_fetchhead_foreach
(
g_repo
,
assert_none_for_merge
,
NULL
));
git_remote_free
(
remote
);
}
void
test_fetchhead_nonetwork__quote_in_branch_name
(
void
)
{
cl_set_cleanup
(
&
cleanup_repository
,
"./test1"
);
...
...
tests/repo/init.c
View file @
8462f7f9
...
...
@@ -688,3 +688,19 @@ void test_repo_init__defaultbranch_config(void)
git_reference_free
(
head
);
}
void
test_repo_init__defaultbranch_config_empty
(
void
)
{
git_reference
*
head
;
cl_set_cleanup
(
&
cleanup_repository
,
"repo"
);
create_tmp_global_config
(
"tmp_global_path"
,
"init.defaultbranch"
,
""
);
cl_git_pass
(
git_repository_init
(
&
g_repo
,
"repo"
,
0
));
cl_git_pass
(
git_reference_lookup
(
&
head
,
g_repo
,
"HEAD"
));
cl_assert_equal_s
(
"refs/heads/master"
,
git_reference_symbolic_target
(
head
));
git_reference_free
(
head
);
}
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