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
728d6829
Commit
728d6829
authored
Feb 28, 2021
by
Waqar Ahmed
Browse files
Send error messages from file history widget on failure
parent
1bb810c6
Changes
4
Hide whitespace changes
Inline
Side-by-side
addons/project/filehistorywidget.cpp
View file @
728d6829
...
...
@@ -11,7 +11,7 @@
#include <KLocalizedString>
// git log --format=%H%n%aN%n%aE%n%at%n%ct%n%P%n%B --author-date-order
static
QList
<
QByteArray
>
getFileHistory
(
const
QString
&
file
)
QList
<
QByteArray
>
FileHistoryWidget
::
getFileHistory
(
const
QString
&
file
)
{
QProcess
git
;
git
.
setWorkingDirectory
(
QFileInfo
(
file
).
absolutePath
());
...
...
@@ -22,7 +22,11 @@ static QList<QByteArray> getFileHistory(const QString &file)
file
};
git
.
start
(
QStringLiteral
(
"git"
),
args
,
QProcess
::
ReadOnly
);
if
(
git
.
waitForStarted
()
&&
git
.
waitForFinished
(
-
1
))
{
return
git
.
readAll
().
split
(
0x00
);
if
(
git
.
exitStatus
()
==
QProcess
::
NormalExit
&&
git
.
exitCode
()
==
0
)
{
return
git
.
readAll
().
split
(
0x00
);
}
else
{
Q_EMIT
errorMessage
(
i18n
(
"Failed to get file history: %1"
,
QString
::
fromUtf8
(
git
.
readAllStandardError
())),
true
);
}
}
return
{};
}
...
...
@@ -137,7 +141,7 @@ public:
QRect
prect
=
opt
.
rect
;
const
int
ascent
=
(
opt
.
fontMetrics
.
ascent
()
/
2
);
//
const int ascent = (opt.fontMetrics.ascent() / 2);
// draw line
// prect.setX(prect.x() + ascent + 2);
...
...
addons/project/filehistorywidget.h
View file @
728d6829
...
...
@@ -15,6 +15,8 @@ private Q_SLOTS:
void
itemClicked
(
const
QModelIndex
&
idx
);
private:
QList
<
QByteArray
>
getFileHistory
(
const
QString
&
file
);
QPushButton
m_backBtn
;
QListView
*
m_listView
;
QString
m_file
;
...
...
@@ -22,6 +24,7 @@ private:
Q_SIGNALS:
void
backClicked
();
void
commitClicked
(
const
QString
&
file
,
const
QByteArray
&
contents
);
void
errorMessage
(
const
QString
&
msg
,
bool
warn
);
};
#endif // FILEHISTORYWIDGET_H
addons/project/gitwidget.cpp
View file @
728d6829
...
...
@@ -109,7 +109,7 @@ void GitWidget::initGitExe()
git
.
start
(
QProcess
::
ReadOnly
);
if
(
git
.
waitForStarted
()
&&
git
.
waitForFinished
(
-
1
))
{
if
(
git
.
exitStatus
()
!=
QProcess
::
NormalExit
||
git
.
exitCode
()
!=
0
)
{
sendMessage
(
i18n
(
"Failed to find .git directory
. T
hings may not work correctly
. Error:
\n
%1"
,
QString
::
fromUtf8
(
git
.
readAllStandardError
())),
true
);
sendMessage
(
i18n
(
"Failed to find .git directory
, t
hings may not work correctly
:
%1"
,
QString
::
fromUtf8
(
git
.
readAllStandardError
())),
true
);
m_gitPath
=
m_project
->
baseDir
();
return
;
}
...
...
@@ -176,7 +176,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
();
}
...
...
@@ -249,7 +249,7 @@ void GitWidget::openAtHEAD(const QString &file)
connect
(
&
git
,
&
QProcess
::
finished
,
this
,
[
this
,
file
](
int
exitCode
,
QProcess
::
ExitStatus
es
)
{
disconnect
(
&
git
,
&
QProcess
::
finished
,
nullptr
,
nullptr
);
if
(
es
!=
QProcess
::
NormalExit
||
exitCode
!=
0
)
{
sendMessage
(
i18n
(
"Failed to open file at HEAD
. Error:
\n
%1"
,
QString
::
fromUtf8
(
git
.
readAllStandardError
())),
true
);
sendMessage
(
i18n
(
"Failed to open file at HEAD
:
%1"
,
QString
::
fromUtf8
(
git
.
readAllStandardError
())),
true
);
}
else
{
openTempFile
(
QFileInfo
(
file
).
fileName
(),
QStringLiteral
(
"XXXXXX - (HEAD) - %1"
),
git
.
readAllStandardOutput
());
}
...
...
@@ -275,7 +275,7 @@ void GitWidget::showDiff(const QString &file, bool staged)
connect
(
&
git
,
&
QProcess
::
finished
,
this
,
[
this
,
file
,
staged
](
int
exitCode
,
QProcess
::
ExitStatus
es
)
{
disconnect
(
&
git
,
&
QProcess
::
finished
,
nullptr
,
nullptr
);
if
(
es
!=
QProcess
::
NormalExit
||
exitCode
!=
0
)
{
sendMessage
(
i18n
(
"Failed to get Diff of file
. Error:
\n
%1"
,
QString
::
fromUtf8
(
git
.
readAllStandardError
())),
true
);
sendMessage
(
i18n
(
"Failed to get Diff of file
:
%1"
,
QString
::
fromUtf8
(
git
.
readAllStandardError
())),
true
);
}
else
{
const
QString
filename
=
file
.
isEmpty
()
?
QString
()
:
QFileInfo
(
file
).
fileName
();
...
...
@@ -358,7 +358,7 @@ void GitWidget::commitChanges(const QString &msg, const QString &desc, bool sign
// sever connection
disconnect
(
&
git
,
&
QProcess
::
finished
,
nullptr
,
nullptr
);
if
(
es
!=
QProcess
::
NormalExit
||
exitCode
!=
0
)
{
sendMessage
(
i18n
(
"Failed to commit
.
\n
%1"
,
QString
::
fromUtf8
(
git
.
readAllStandardError
())),
true
);
sendMessage
(
i18n
(
"Failed to commit
:
%1"
,
QString
::
fromUtf8
(
git
.
readAllStandardError
())),
true
);
}
else
{
m_commitMessage
.
clear
();
getStatus
();
...
...
@@ -416,7 +416,7 @@ void GitWidget::applyDiff(const QString &fileName, bool staged, bool hunk, KText
delete
file
;
disconnect
(
&
git
,
&
QProcess
::
finished
,
nullptr
,
nullptr
);
if
(
es
!=
QProcess
::
NormalExit
||
exitCode
!=
0
)
{
sendMessage
(
QStringLiteral
(
"Failed to stage
\n
"
)
+
QString
::
fromUtf8
(
git
.
readAllStandardError
()),
true
);
sendMessage
(
i18n
(
"Failed to stage
: %1"
,
QString
::
fromUtf8
(
git
.
readAllStandardError
())
)
,
true
);
}
else
{
// close and reopen doc to show updated diff
if
(
v
&&
v
->
document
())
{
...
...
addons/project/kateprojectview.cpp
View file @
728d6829
...
...
@@ -150,6 +150,14 @@ void KateProjectView::showFileGitHistory(const QString &file)
auto
fhs
=
new
FileHistoryWidget
(
file
);
connect
(
fhs
,
&
FileHistoryWidget
::
backClicked
,
this
,
&
KateProjectView
::
setTreeViewAsCurrent
);
connect
(
fhs
,
&
FileHistoryWidget
::
commitClicked
,
this
,
&
KateProjectView
::
showDiffInFixedView
);
connect
(
fhs
,
&
FileHistoryWidget
::
errorMessage
,
m_pluginView
,
[
this
](
const
QString
&
s
,
bool
warn
)
{
QVariantMap
genericMessage
;
genericMessage
.
insert
(
QStringLiteral
(
"type"
),
warn
?
QStringLiteral
(
"Error"
)
:
QStringLiteral
(
"Info"
));
genericMessage
.
insert
(
QStringLiteral
(
"category"
),
i18n
(
"Git"
));
genericMessage
.
insert
(
QStringLiteral
(
"categoryIcon"
),
QIcon
(
QStringLiteral
(
":/icons/icons/sc-apps-git.svg"
)));
genericMessage
.
insert
(
QStringLiteral
(
"text"
),
s
);
Q_EMIT
m_pluginView
->
message
(
genericMessage
);
});
m_stackWidget
->
addWidget
(
fhs
);
m_stackWidget
->
setCurrentWidget
(
fhs
);
}
...
...
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