Skip to content

Commit

Permalink
Fixed setting upstream for local branch
Browse files Browse the repository at this point in the history
  • Loading branch information
nexus6-haiku committed Nov 7, 2023
1 parent 68e1a3f commit 67f9c0c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/helpers/git/GitRepository.cpp
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include <stdexcept>
#include <map>

#include "Utils.h"

namespace Genio::Git {

GitRepository::GitRepository(const path& path)
Expand Down Expand Up @@ -116,34 +118,32 @@ namespace Genio::Git {
status = git_checkout_init_options(&opts, GIT_CHECKOUT_OPTIONS_VERSION);
if (status < 0)
throw GitException(status, git_error_last()->message);

opts.notify_flags = GIT_CHECKOUT_NOTIFY_CONFLICT;
opts.checkout_strategy = GIT_CHECKOUT_SAFE;
opts.notify_cb = checkout_notify;
opts.notify_payload = &files;

status = git_revparse_single(&tree, fRepository, branchName.String());
if (status < 0)
throw GitException(status, git_error_last()->message);

// if the target branch is remote and a corresponding local branch does not exist, we need
// to create a local branch first, set the remote tracking then checkout
if (branchName.StartsWith("origin")) {
remoteBranchName = branchName;
branchName.RemoveFirst("origin/");

git_reference* ref = nullptr;
status = git_branch_create(&ref, fRepository, branchName.String(), (git_commit*)tree, false);
if (status > 0) {
if (status >= 0) {
status = git_branch_set_upstream(ref, remoteBranchName.String());
if (status < 0)
throw GitException(status, git_error_last()->message);

git_reference_free(ref);
}

}

status = git_checkout_tree(fRepository, tree, &opts);
if (status < 0) {
throw GitException(status, git_error_last()->message, files);
Expand Down
Empty file modified src/helpers/git/GitRepository.h
100755 → 100644
Empty file.

0 comments on commit 67f9c0c

Please sign in to comment.