Create local branches at branch switch
This commit is contained in:
+13
-2
@@ -126,9 +126,20 @@ Page {
|
|||||||
ComboBox {
|
ComboBox {
|
||||||
id: branchSelector
|
id: branchSelector
|
||||||
model: addon.branches
|
model: addon.branches
|
||||||
onModelChanged: currentIndex = find(addon.currentBranch)
|
|
||||||
Component.onCompleted: currentIndex = find(addon.currentBranch)
|
|
||||||
onActivated: addon.currentBranch = currentText
|
onActivated: addon.currentBranch = currentText
|
||||||
|
implicitContentWidthPolicy: ComboBox.WidestText
|
||||||
|
Connections
|
||||||
|
{
|
||||||
|
target: addon
|
||||||
|
function onCurrentBranchChanged()
|
||||||
|
{
|
||||||
|
branchSelector.currentIndex = branchSelector.find(addon.currentBranch)
|
||||||
|
}
|
||||||
|
function onBranchesChanged()
|
||||||
|
{
|
||||||
|
branchSelector.currentIndex = branchSelector.find(addon.currentBranch)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
RowLayout {
|
RowLayout {
|
||||||
spacing: 0
|
spacing: 0
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
cmake_minimum_required(VERSION 3.1.0)
|
cmake_minimum_required(VERSION 3.5.0)
|
||||||
project(GitAddonsManager LANGUAGES CXX)
|
project(GitAddonsManager LANGUAGES CXX)
|
||||||
find_package(Qt6 COMPONENTS Quick Core QuickControls2 Concurrent Network Widgets REQUIRED)
|
find_package(Qt6 COMPONENTS Quick Core QuickControls2 Concurrent Network Widgets REQUIRED)
|
||||||
find_package(Qt6LinguistTools)
|
find_package(Qt6LinguistTools)
|
||||||
|
|||||||
@@ -59,6 +59,26 @@ void Addon::update()
|
|||||||
auto tr = remoteRefForBranch(m_currentBranch.toLocal8Bit());
|
auto tr = remoteRefForBranch(m_currentBranch.toLocal8Bit());
|
||||||
AutoPtr ubr(&git_reference_free);
|
AutoPtr ubr(&git_reference_free);
|
||||||
|
|
||||||
|
if (git_reference_is_remote(lbr))
|
||||||
|
{
|
||||||
|
git_buf buf = GIT_BUF_INIT_CONST(0, nullptr);
|
||||||
|
AutoPtr<git_buf> remote(&buf, git_buf_free);
|
||||||
|
check_git_return(git_branch_remote_name(remote, m_repo.get(), git_reference_name(lbr)));
|
||||||
|
git_reference* nlbr = nullptr;
|
||||||
|
git_commit* commit = nullptr;
|
||||||
|
AutoPtr<git_commit> commit_g(commit, git_commit_free);
|
||||||
|
check_git_return(git_commit_lookup(&commit, m_repo.get(), git_reference_target(tr)));
|
||||||
|
QString newName;
|
||||||
|
if (strcmp(buf.ptr, "origin") == 0)
|
||||||
|
newName = m_currentBranch.sliced(7);
|
||||||
|
else
|
||||||
|
newName = QString(m_currentBranch).replace(strlen(buf.ptr), 1, '_');
|
||||||
|
if (git_branch_create(&nlbr, m_repo.get(), newName.toLocal8Bit(), commit, 1) != GIT_OK)
|
||||||
|
git_branch_lookup(&nlbr, m_repo.get(), newName.toLocal8Bit(), GIT_BRANCH_LOCAL);
|
||||||
|
check_git_return(git_branch_set_upstream(nlbr, git_reference_name(lbr)));
|
||||||
|
lbr.reset(nlbr);
|
||||||
|
}
|
||||||
|
|
||||||
if (!git_branch_is_head(lbr))
|
if (!git_branch_is_head(lbr))
|
||||||
check_git_return(git_repository_set_head(m_repo.get(), git_reference_name(lbr)));
|
check_git_return(git_repository_set_head(m_repo.get(), git_reference_name(lbr)));
|
||||||
|
|
||||||
@@ -67,7 +87,7 @@ void Addon::update()
|
|||||||
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
|
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
|
||||||
opts.checkout_strategy = GIT_CHECKOUT_FORCE;
|
opts.checkout_strategy = GIT_CHECKOUT_FORCE;
|
||||||
check_git_return(git_checkout_head(m_repo.get(), &opts));
|
check_git_return(git_checkout_head(m_repo.get(), &opts));
|
||||||
}, [this](){updateGitStatus();});
|
}, [this](){scanBranches(); updateGitStatus();});
|
||||||
unpackSubfolders();
|
unpackSubfolders();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,10 +118,11 @@ void Addon::scanBranches()
|
|||||||
if (git_branch_is_head(ref)) {
|
if (git_branch_is_head(ref)) {
|
||||||
data.cb = bname;
|
data.cb = bname;
|
||||||
git_buf buf = GIT_BUF_INIT_CONST(0, nullptr);
|
git_buf buf = GIT_BUF_INIT_CONST(0, nullptr);
|
||||||
|
AutoPtr<git_buf> buf_g(&buf, git_buf_free);
|
||||||
(git_reference_is_remote(ref) ?
|
(git_reference_is_remote(ref) ?
|
||||||
git_branch_remote_name :
|
git_branch_remote_name :
|
||||||
git_branch_upstream_remote
|
git_branch_upstream_remote
|
||||||
)(&buf, m_repo.get(), git_reference_name(ref));
|
)(&buf, m_repo.get(), git_reference_name(ref));
|
||||||
data.cr = buf.ptr;
|
data.cr = buf.ptr;
|
||||||
}
|
}
|
||||||
ref.reset();
|
ref.reset();
|
||||||
@@ -122,6 +143,7 @@ void Addon::scanBranches()
|
|||||||
}
|
}
|
||||||
if (!ref) break;
|
if (!ref) break;
|
||||||
git_buf buf = GIT_BUF_INIT_CONST(0, nullptr);
|
git_buf buf = GIT_BUF_INIT_CONST(0, nullptr);
|
||||||
|
AutoPtr<git_buf> buf_g(&buf, git_buf_free);
|
||||||
if (!f(&buf, m_repo.get(), git_reference_name(ref))) {
|
if (!f(&buf, m_repo.get(), git_reference_name(ref))) {
|
||||||
data.cr = buf.ptr;
|
data.cr = buf.ptr;
|
||||||
data.cb = match.captured(1);
|
data.cb = match.captured(1);
|
||||||
@@ -278,6 +300,12 @@ void Addon::updateGitStatus()
|
|||||||
return GitStatusFlag::UpToDate;
|
return GitStatusFlag::UpToDate;
|
||||||
AutoPtr lr(&git_reference_free);
|
AutoPtr lr(&git_reference_free);
|
||||||
check_git_return(git_repository_head(&lr, m_repo.get()));
|
check_git_return(git_repository_head(&lr, m_repo.get()));
|
||||||
|
|
||||||
|
const char* name = nullptr;
|
||||||
|
|
||||||
|
if (git_reference_is_remote(lr) || git_branch_name(&name, lr) == GIT_OK && m_currentBranch != name)
|
||||||
|
return GitStatusFlag::Diverged;
|
||||||
|
|
||||||
AutoPtr uc(&git_annotated_commit_free);
|
AutoPtr uc(&git_annotated_commit_free);
|
||||||
AutoPtr lc(&git_annotated_commit_free);
|
AutoPtr lc(&git_annotated_commit_free);
|
||||||
check_git_return(git_annotated_commit_from_ref(&uc, m_repo.get(), tr));
|
check_git_return(git_annotated_commit_from_ref(&uc, m_repo.get(), tr));
|
||||||
@@ -348,8 +376,8 @@ void Addon::uninstall()
|
|||||||
removeSubfolders();
|
removeSubfolders();
|
||||||
closeRepo();
|
closeRepo();
|
||||||
delegate("Removing addon folder", [this](){
|
delegate("Removing addon folder", [this](){
|
||||||
removeFolder(m_path + "/" + m_name);
|
removeFolder(m_path + "/" + m_name);
|
||||||
}, [](){Control::instance()->scanForAddons();});
|
}, [](){Control::instance()->scanForAddons();});
|
||||||
}
|
}
|
||||||
|
|
||||||
void Addon::setSubfolders(QStringList subfolders)
|
void Addon::setSubfolders(QStringList subfolders)
|
||||||
@@ -447,7 +475,7 @@ void Addon::unpackSubfolders(){
|
|||||||
}
|
}
|
||||||
errors << QString("The folder \"%1\" already existed and has been renamed to \"%2\"").arg(subfn, dest.fileName());
|
errors << QString("The folder \"%1\" already existed and has been renamed to \"%2\"").arg(subfn, dest.fileName());
|
||||||
}
|
}
|
||||||
#ifdef Q_OS_WIN32
|
#ifdef Q_OS_WIN32
|
||||||
QString link = subfn;
|
QString link = subfn;
|
||||||
link.replace("/","\\");
|
link.replace("/","\\");
|
||||||
QString target = "./"+m_name+"/"+subfn;
|
QString target = "./"+m_name+"/"+subfn;
|
||||||
@@ -458,9 +486,9 @@ void Addon::unpackSubfolders(){
|
|||||||
link_w[pos] = '\0';
|
link_w[pos] = '\0';
|
||||||
pos = target.toWCharArray(target_w);
|
pos = target.toWCharArray(target_w);
|
||||||
target_w[pos] = '\0';
|
target_w[pos] = '\0';
|
||||||
#else
|
#else
|
||||||
QFile::link("./"+m_name+"/"+subfn, subfn);
|
QFile::link("./"+m_name+"/"+subfn, subfn);
|
||||||
#endif
|
#endif
|
||||||
if (!QFileInfo(subfn).exists()) {
|
if (!QFileInfo(subfn).exists()) {
|
||||||
dir.rename(subfn, "../"+subfn);
|
dir.rename(subfn, "../"+subfn);
|
||||||
}
|
}
|
||||||
@@ -471,10 +499,10 @@ void Addon::unpackSubfolders(){
|
|||||||
}
|
}
|
||||||
return errors;
|
return errors;
|
||||||
}, [this](auto errors){
|
}, [this](auto errors){
|
||||||
if (errors.size() > 0) {
|
if (errors.size() > 0) {
|
||||||
setStatus(Status::Error);
|
setStatus(Status::Error);
|
||||||
//setStatusMessage(errors.join('\n'));
|
//setStatusMessage(errors.join('\n'));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -584,13 +612,13 @@ QFuture<void> Addon::updateIfBehind()
|
|||||||
{
|
{
|
||||||
std::shared_ptr<QPromise<void>> p(new QPromise<void>());
|
std::shared_ptr<QPromise<void>> p(new QPromise<void>());
|
||||||
delegate("UpdateIfBehind", [this](){
|
delegate("UpdateIfBehind", [this](){
|
||||||
},[this, p](){
|
},[this, p](){
|
||||||
if (m_gitStatus == Addon::GitStatusFlag::Behind)
|
if (m_gitStatus == Addon::GitStatusFlag::Behind)
|
||||||
update();
|
update();
|
||||||
delegate("Finished", [p](){
|
delegate("Finished", [p](){
|
||||||
p->finish();
|
p->finish();
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
});
|
||||||
return p->future();
|
return p->future();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user