Skip to content

Commit 8643b52

Browse files
Alexander OvchinnikovAlexander Ovchinnikov
authored andcommitted
Revert "Merge pull request libgit2#5775 from libgit2/ethomson/clone_branch"
This reverts commit 487f2a8, reversing changes made to c6cf7f0.
1 parent fabacb7 commit 8643b52

File tree

2 files changed

+21
-50
lines changed

2 files changed

+21
-50
lines changed

src/clone.c

Lines changed: 21 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -162,45 +162,16 @@ static int update_head_to_default(git_repository *repo)
162162
return error;
163163
}
164164

165-
static int update_remote_head_byname(
166-
git_repository *repo,
167-
const char *remote_name,
168-
const char *tracking_branch_name,
169-
const char *reflog_message)
170-
{
171-
git_buf tracking_head_name = GIT_BUF_INIT;
172-
git_reference *remote_head = NULL;
173-
int error;
174-
175-
if ((error = git_buf_printf(&tracking_head_name,
176-
"%s%s/%s",
177-
GIT_REFS_REMOTES_DIR,
178-
remote_name,
179-
GIT_HEAD_FILE)) < 0)
180-
goto cleanup;
181-
182-
error = git_reference_symbolic_create(
183-
&remote_head,
184-
repo,
185-
git_buf_cstr(&tracking_head_name),
186-
tracking_branch_name,
187-
true,
188-
reflog_message);
189-
190-
cleanup:
191-
git_reference_free(remote_head);
192-
git_buf_dispose(&tracking_head_name);
193-
return error;
194-
}
195-
196165
static int update_remote_head(
197166
git_repository *repo,
198167
git_remote *remote,
199168
git_buf *target,
200169
const char *reflog_message)
201170
{
202171
git_refspec *refspec;
203-
git_buf tracking_branch_name = GIT_BUF_INIT;
172+
git_reference *remote_head = NULL;
173+
git_buf remote_head_name = GIT_BUF_INIT;
174+
git_buf remote_branch_name = GIT_BUF_INIT;
204175
int error;
205176

206177
/* Determine the remote tracking ref name from the local branch */
@@ -213,19 +184,30 @@ static int update_remote_head(
213184
}
214185

215186
if ((error = git_refspec_transform(
216-
&tracking_branch_name,
187+
&remote_branch_name,
217188
refspec,
218189
git_buf_cstr(target))) < 0)
219190
goto cleanup;
220191

221-
error = update_remote_head_byname(
222-
repo,
192+
if ((error = git_buf_printf(&remote_head_name,
193+
"%s%s/%s",
194+
GIT_REFS_REMOTES_DIR,
223195
git_remote_name(remote),
224-
git_buf_cstr(&tracking_branch_name),
196+
GIT_HEAD_FILE)) < 0)
197+
goto cleanup;
198+
199+
error = git_reference_symbolic_create(
200+
&remote_head,
201+
repo,
202+
git_buf_cstr(&remote_head_name),
203+
git_buf_cstr(&remote_branch_name),
204+
true,
225205
reflog_message);
226206

227207
cleanup:
228-
git_buf_dispose(&tracking_branch_name);
208+
git_reference_free(remote_head);
209+
git_buf_dispose(&remote_branch_name);
210+
git_buf_dispose(&remote_head_name);
229211
return error;
230212
}
231213

@@ -295,11 +277,8 @@ static int update_head_to_branch(
295277
if ((retcode = git_reference_lookup(&remote_ref, repo, git_buf_cstr(&remote_branch_name))) < 0)
296278
goto cleanup;
297279

298-
if ((retcode = update_head_to_new_branch(repo, git_reference_target(remote_ref), branch,
299-
reflog_message)) < 0)
300-
goto cleanup;
301-
302-
retcode = update_remote_head_byname(repo, remote_name, remote_branch_name.ptr, reflog_message);
280+
retcode = update_head_to_new_branch(repo, git_reference_target(remote_ref), branch,
281+
reflog_message);
303282

304283
cleanup:
305284
git_reference_free(remote_ref);

tests/clone/nonetwork.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,6 @@ void test_clone_nonetwork__can_prevent_the_checkout_of_a_standard_repo(void)
158158

159159
void test_clone_nonetwork__can_checkout_given_branch(void)
160160
{
161-
git_reference *remote_head;
162-
163161
g_options.checkout_branch = "test";
164162
cl_git_pass(git_clone(&g_repo, cl_git_fixture_url("testrepo.git"), "./foo", &g_options));
165163

@@ -169,12 +167,6 @@ void test_clone_nonetwork__can_checkout_given_branch(void)
169167
cl_assert_equal_s(git_reference_name(g_ref), "refs/heads/test");
170168

171169
cl_assert(git_path_exists("foo/readme.txt"));
172-
173-
cl_git_pass(git_reference_lookup(&remote_head, g_repo, "refs/remotes/origin/HEAD"));
174-
cl_assert_equal_i(GIT_REFERENCE_SYMBOLIC, git_reference_type(remote_head));
175-
cl_assert_equal_s("refs/remotes/origin/test", git_reference_symbolic_target(remote_head));
176-
177-
git_reference_free(remote_head);
178170
}
179171

180172
static int clone_cancel_fetch_transfer_progress_cb(

0 commit comments

Comments
 (0)