Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Utilities
Kate
Commits
d273cd62
Commit
d273cd62
authored
Mar 02, 2021
by
Waqar Ahmed
Browse files
Git push: initial commit
Signed-off-by:
Waqar Ahmed
<
waqar.17a@gmail.com
>
parent
bd4b0001
Changes
6
Hide whitespace changes
Inline
Side-by-side
addons/project/CMakeLists.txt
View file @
d273cd62
...
...
@@ -65,6 +65,7 @@ target_sources(
gitcommitdialog.cpp
stashdialog.cpp
quickdialog.cpp
pushpulldialog.cpp
tools/kateprojectcodeanalysistoolcppcheck.cpp
tools/kateprojectcodeanalysistoolflake8.cpp
...
...
addons/project/gitwidget.cpp
View file @
d273cd62
...
...
@@ -10,6 +10,7 @@
#include "gitstatusmodel.h"
#include "kateproject.h"
#include "kateprojectpluginview.h"
#include "pushpulldialog.h"
#include "stashdialog.h"
#include <QContextMenuEvent>
...
...
@@ -48,13 +49,13 @@ GitWidget::GitWidget(KateProject *project, KTextEditor::MainWindow *mainWindow,
,
m_mainWin
(
mainWindow
)
,
m_pluginView
(
pluginView
)
{
m_commitBtn
=
new
QToolButton
(
this
);
m_treeView
=
new
QTreeView
(
this
);
initGitExe
();
buildMenu
();
m_menuBtn
=
new
QToolButton
(
this
);
m_menuBtn
=
new
QToolButton
;
m_menuBtn
->
setIcon
(
QIcon
::
fromTheme
(
QStringLiteral
(
"application-menu"
)));
m_menuBtn
->
setAutoRaise
(
true
);
m_menuBtn
->
setMenu
(
m_gitMenu
);
m_menuBtn
->
setArrowType
(
Qt
::
NoArrow
);
...
...
@@ -63,21 +64,47 @@ GitWidget::GitWidget(KateProject *project, KTextEditor::MainWindow *mainWindow,
m_menuBtn
->
showMenu
();
});
m_
menuBtn
->
setIcon
(
QIcon
::
fromTheme
(
QStringLiteral
(
"application-menu"
)))
;
m_
commitBtn
=
new
QToolButton
;
m_commitBtn
->
setText
(
i18n
(
"Commit"
));
m_commitBtn
->
setIcon
(
QIcon
::
fromTheme
(
QStringLiteral
(
"svn-commit"
)));
// ":/kxmlgui5/kateproject/git-commit-dark.svg"
m_commitBtn
->
setAutoRaise
(
true
);
m_commitBtn
->
setToolButtonStyle
(
Qt
::
ToolButtonTextBesideIcon
);
m_commitBtn
->
setSizePolicy
(
QSizePolicy
::
Minimum
,
m_commitBtn
->
sizePolicy
().
verticalPolicy
());
m_pushBtn
=
new
QToolButton
;
m_pushBtn
->
setIcon
(
QIcon
::
fromTheme
(
QStringLiteral
(
"arrow-up"
)));
m_pushBtn
->
setToolTip
(
i18n
(
"Git push"
));
m_pushBtn
->
setAutoRaise
(
true
);
m_pushBtn
->
setSizePolicy
(
QSizePolicy
::
Minimum
,
m_commitBtn
->
sizePolicy
().
verticalPolicy
());
connect
(
m_pushBtn
,
&
QToolButton
::
clicked
,
this
,
[
this
]()
{
PushPullDialog
ppd
(
m_mainWin
->
window
(),
m_gitPath
);
connect
(
&
ppd
,
&
PushPullDialog
::
runGitCommand
,
this
,
&
GitWidget
::
runPushPullCmd
);
ppd
.
openDialog
(
PushPullDialog
::
Push
);
});
m_pullBtn
=
new
QToolButton
;
m_pullBtn
->
setIcon
(
QIcon
::
fromTheme
(
QStringLiteral
(
"arrow-down"
)));
m_pullBtn
->
setToolTip
(
i18n
(
"Git pull"
));
m_pullBtn
->
setAutoRaise
(
true
);
m_pullBtn
->
setSizePolicy
(
QSizePolicy
::
Minimum
,
m_commitBtn
->
sizePolicy
().
verticalPolicy
());
connect
(
m_pullBtn
,
&
QToolButton
::
clicked
,
this
,
[
this
]()
{
PushPullDialog
ppd
(
m_mainWin
->
window
(),
m_gitPath
);
connect
(
&
ppd
,
&
PushPullDialog
::
runGitCommand
,
this
,
&
GitWidget
::
runPushPullCmd
);
ppd
.
openDialog
(
PushPullDialog
::
Pull
);
});
QVBoxLayout
*
layout
=
new
QVBoxLayout
;
layout
->
setSpacing
(
0
);
layout
->
setContentsMargins
(
0
,
0
,
0
,
0
);
QHBoxLayout
*
btnsLayout
=
new
QHBoxLayout
;
btnsLayout
->
setContentsMargins
(
0
,
0
,
0
,
0
);
btnsLayout
->
addWidget
(
m_commitBtn
);
btnsLayout
->
addWidget
(
m_pushBtn
);
btnsLayout
->
addWidget
(
m_pullBtn
);
btnsLayout
->
addWidget
(
m_menuBtn
);
btnsLayout
->
setStretch
(
0
,
1
);
layout
->
addLayout
(
btnsLayout
);
layout
->
addWidget
(
m_treeView
);
...
...
@@ -176,7 +203,7 @@ void GitWidget::runGitCmd(const QStringList &args, const QString &i18error)
// sever connection
disconnect
(
&
git
,
&
QProcess
::
finished
,
nullptr
,
nullptr
);
if
(
es
!=
QProcess
::
NormalExit
||
exitCode
!=
0
)
{
sendMessage
(
i18error
+
QStringLiteral
(
"
\n
"
)
+
QString
::
fromUtf8
(
git
.
readAllStandardError
()),
true
);
sendMessage
(
i18error
+
QStringLiteral
(
"
:
"
)
+
QString
::
fromUtf8
(
git
.
readAllStandardError
()),
true
);
}
else
{
getStatus
();
}
...
...
@@ -185,6 +212,32 @@ void GitWidget::runGitCmd(const QStringList &args, const QString &i18error)
git
.
start
(
QProcess
::
ReadOnly
);
}
void
GitWidget
::
runPushPullCmd
(
const
QStringList
&
args
)
{
disconnect
(
&
git
,
&
QProcess
::
finished
,
nullptr
,
nullptr
);
connect
(
&
git
,
&
QProcess
::
finished
,
this
,
[
this
](
int
exitCode
,
QProcess
::
ExitStatus
es
)
{
// sever connection
disconnect
(
&
git
,
&
QProcess
::
finished
,
nullptr
,
nullptr
);
if
(
es
!=
QProcess
::
NormalExit
||
exitCode
!=
0
)
{
sendMessage
(
i18n
(
"git push error: %1"
,
QString
::
fromUtf8
(
git
.
readAllStandardError
())),
true
);
}
else
{
sendMessage
(
i18n
(
"git push finished"
),
false
);
getStatus
();
}
});
git
.
setArguments
(
args
);
git
.
start
(
QProcess
::
ReadOnly
);
// kill after 40 seconds
QTimer
::
singleShot
(
40000
,
this
,
[
this
]
{
if
(
git
.
state
()
==
QProcess
::
Running
)
{
sendMessage
(
i18n
(
"Git operation failed. Killing..."
),
true
);
git
.
kill
();
}
});
}
void
GitWidget
::
stage
(
const
QStringList
&
files
,
bool
)
{
if
(
files
.
isEmpty
())
{
...
...
addons/project/gitwidget.h
View file @
d273cd62
...
...
@@ -52,6 +52,8 @@ public:
private:
QToolButton
*
m_menuBtn
;
QToolButton
*
m_commitBtn
;
QToolButton
*
m_pushBtn
;
QToolButton
*
m_pullBtn
;
QTreeView
*
m_treeView
;
GitStatusModel
*
m_model
;
KateProject
*
m_project
;
...
...
@@ -68,6 +70,7 @@ private:
void
buildMenu
();
void
initGitExe
();
void
runGitCmd
(
const
QStringList
&
args
,
const
QString
&
i18error
);
void
runPushPullCmd
(
const
QStringList
&
args
);
void
stage
(
const
QStringList
&
files
,
bool
=
false
);
void
unstage
(
const
QStringList
&
files
);
void
discard
(
const
QStringList
&
files
);
...
...
addons/project/pushpulldialog.cpp
0 → 100644
View file @
d273cd62
#include "pushpulldialog.h"
#include <QProcess>
PushPullDialog
::
PushPullDialog
(
QWidget
*
mainWindow
,
const
QString
&
repoPath
)
:
QuickDialog
(
mainWindow
)
,
m_repo
(
repoPath
)
{
}
void
PushPullDialog
::
openDialog
(
PushPullDialog
::
Mode
m
)
{
if
(
m
==
Push
)
{
m_lineEdit
.
setText
(
buildPushString
());
}
else
if
(
m
==
Pull
)
{
m_lineEdit
.
setText
(
buildPullString
());
}
updateViewGeometry
();
setFocus
();
exec
();
}
/**
* This is not for display, hence not reusing gitutils here
*/
static
QString
currentBranchName
(
const
QString
&
repo
)
{
QProcess
git
;
git
.
setWorkingDirectory
(
repo
);
QStringList
args
{
QStringLiteral
(
"symbolic-ref"
),
QStringLiteral
(
"--short"
),
QStringLiteral
(
"HEAD"
)};
git
.
start
(
QStringLiteral
(
"git"
),
args
,
QProcess
::
ReadOnly
);
if
(
git
.
waitForStarted
()
&&
git
.
waitForFinished
(
-
1
))
{
if
(
git
.
exitStatus
()
==
QProcess
::
NormalExit
&&
git
.
exitCode
()
==
0
)
{
return
QString
::
fromUtf8
(
git
.
readAllStandardOutput
().
trimmed
());
}
}
// give up
return
QString
();
}
static
QStringList
remotesList
(
const
QString
&
repo
)
{
QProcess
git
;
git
.
setWorkingDirectory
(
repo
);
QStringList
args
{
QStringLiteral
(
"remote"
)};
git
.
start
(
QStringLiteral
(
"git"
),
args
,
QProcess
::
ReadOnly
);
if
(
git
.
waitForStarted
()
&&
git
.
waitForFinished
(
-
1
))
{
if
(
git
.
exitStatus
()
==
QProcess
::
NormalExit
&&
git
.
exitCode
()
==
0
)
{
return
QString
::
fromUtf8
(
git
.
readAllStandardOutput
()).
split
(
QLatin1Char
(
'\n'
));
}
}
// give up
return
{};
}
QString
PushPullDialog
::
buildPushString
()
{
auto
br
=
currentBranchName
(
m_repo
);
if
(
br
.
isEmpty
())
{
return
QStringLiteral
(
"git push"
);
}
auto
remotes
=
remotesList
(
m_repo
);
if
(
!
remotes
.
contains
(
QStringLiteral
(
"origin"
)))
{
return
QStringLiteral
(
"git push"
);
}
return
QStringLiteral
(
"git push %1 %2"
).
arg
(
QStringLiteral
(
"origin"
)).
arg
(
br
);
}
QString
PushPullDialog
::
buildPullString
()
{
auto
br
=
currentBranchName
(
m_repo
);
if
(
br
.
isEmpty
())
{
return
QStringLiteral
(
"git pull"
);
}
auto
remotes
=
remotesList
(
m_repo
);
if
(
!
remotes
.
contains
(
QStringLiteral
(
"origin"
)))
{
return
QStringLiteral
(
"git pull"
);
}
return
QStringLiteral
(
"git pull %1 %2"
).
arg
(
QStringLiteral
(
"origin"
)).
arg
(
br
);
}
void
PushPullDialog
::
slotReturnPressed
()
{
if
(
!
m_lineEdit
.
text
().
isEmpty
())
{
auto
args
=
m_lineEdit
.
text
().
split
(
QLatin1Char
(
' '
));
if
(
args
.
first
()
==
QStringLiteral
(
"git"
))
{
args
.
pop_front
();
Q_EMIT
runGitCommand
(
args
);
}
}
clearLineEdit
();
hide
();
}
addons/project/pushpulldialog.h
0 → 100644
View file @
d273cd62
#ifndef PUSHPULLDIALOG_H
#define PUSHPULLDIALOG_H
#include "quickdialog.h"
class
PushPullDialog
:
public
QuickDialog
{
Q_OBJECT
public:
PushPullDialog
(
QWidget
*
mainWindow
,
const
QString
&
repo
);
enum
Mode
{
Push
,
Pull
};
void
openDialog
(
Mode
m
);
Q_SIGNAL
void
runGitCommand
(
const
QStringList
&
args
);
private:
QString
buildPushString
();
QString
buildPullString
();
QString
m_repo
;
protected
Q_SLOTS
:
void
slotReturnPressed
()
override
;
};
#endif // PUSHPULLDIALOG_H
addons/project/stashdialog.cpp
View file @
d273cd62
...
...
@@ -143,7 +143,7 @@ StashDialog::StashDialog(GitWidget *gitwidget, QWidget *window)
StyleDelegate
*
delegate
=
new
StyleDelegate
(
this
);
m_treeView
.
setItemDelegateForColumn
(
0
,
delegate
);
connect
(
&
m_lineEdit
,
&
QLineEdit
::
textChanged
,
delegate
,
[
this
,
delegate
](
const
QString
&
string
)
{
connect
(
&
m_lineEdit
,
&
QLineEdit
::
textChanged
,
this
,
[
this
,
delegate
](
const
QString
&
string
)
{
m_proxyModel
->
setFilterString
(
string
);
delegate
->
setFilterString
(
string
);
// reselect first
...
...
Write
Preview
Supports
Markdown
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