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
ef04b65e
Commit
ef04b65e
authored
Feb 14, 2021
by
Waqar Ahmed
Browse files
Implement Unstaging backend/UI
parent
b32d8c19
Changes
3
Hide whitespace changes
Inline
Side-by-side
addons/project/gitstatusmodel.h
View file @
ef04b65e
...
...
@@ -31,6 +31,11 @@ public:
return
m_nodes
[
3
];
}
const
QVector
<
GitUtils
::
StatusItem
>
&
stagedFiles
()
const
{
return
m_nodes
[
0
];
}
const
QVector
<
GitUtils
::
StatusItem
>
&
changedFiles
()
const
{
return
m_nodes
[
1
];
...
...
addons/project/gitwidget.cpp
View file @
ef04b65e
...
...
@@ -95,6 +95,33 @@ void GitWidget::stage(const QString &file, bool untracked)
}
}
void
GitWidget
::
unstage
(
const
QString
&
file
)
{
// git reset -q HEAD --
auto
args
=
QStringList
{
QStringLiteral
(
"reset"
),
QStringLiteral
(
"-q"
),
QStringLiteral
(
"HEAD"
),
QStringLiteral
(
"--"
)};
// all
if
(
file
.
isEmpty
())
{
const
QVector
<
GitUtils
::
StatusItem
>
&
files
=
m_model
->
stagedFiles
();
args
.
reserve
(
args
.
size
()
+
files
.
size
());
for
(
const
auto
&
file
:
files
)
{
args
.
append
(
file
.
file
);
}
}
else
{
// one file
args
.
append
(
file
);
}
git
.
setWorkingDirectory
(
m_project
->
baseDir
());
git
.
setProgram
(
QStringLiteral
(
"git"
));
git
.
setArguments
(
args
);
git
.
start
();
if
(
git
.
waitForStarted
()
&&
git
.
waitForFinished
(
-
1
))
{
getStatus
(
m_project
->
baseDir
());
}
}
void
GitWidget
::
gitStatusReady
()
{
disconnect
(
&
git
,
&
QProcess
::
readyRead
,
this
,
&
GitWidget
::
gitStatusReady
);
...
...
@@ -239,19 +266,25 @@ void GitWidget::treeViewContextMenuEvent(QContextMenuEvent *e)
}
}
else
if
(
type
==
GitStatusModel
::
NodeFile
)
{
QMenu
menu
;
auto
stageAct
=
menu
.
addAction
(
i18n
(
"Stage file"
));
bool
unstaging
=
idx
.
internalId
()
==
GitStatusModel
::
NodeStage
;
auto
stageAct
=
unstaging
?
menu
.
addAction
(
i18n
(
"Unstage file"
))
:
menu
.
addAction
(
i18n
(
"Stage file"
));
auto
act
=
menu
.
exec
(
m_treeView
->
viewport
()
->
mapToGlobal
(
e
->
pos
()));
const
QString
file
=
QString
(
m_project
->
baseDir
()
+
QStringLiteral
(
"/"
)
+
idx
.
data
().
toString
());
if
(
act
==
stageAct
)
{
stage
(
QString
(
m_project
->
baseDir
()
+
QStringLiteral
(
"/"
)
+
idx
.
data
().
toString
()));
if
(
unstaging
)
{
return
unstage
(
file
);
}
return
stage
(
file
);
}
}
else
if
(
type
==
GitStatusModel
::
NodeStage
)
{
QMenu
menu
;
auto
stage
=
menu
.
addAction
(
i18n
(
"Unstage All"
));
auto
act
=
menu
.
exec
(
m_treeView
->
viewport
()
->
mapToGlobal
(
e
->
pos
()));
// git reset -q HEAD --
if
(
act
==
stage
)
{
hideEmptyTreeNodes
(
);
unstage
(
QString
()
);
}
}
}
addons/project/gitwidget.h
View file @
ef04b65e
...
...
@@ -39,6 +39,7 @@ private:
void
getStatus
(
const
QString
&
repo
,
bool
untracked
=
true
,
bool
submodules
=
false
);
void
stage
(
const
QString
&
file
,
bool
untracked
=
false
);
void
unstage
(
const
QString
&
file
);
GitParsedStatus
parseStatus
(
const
QByteArray
&
raw
);
void
hideEmptyTreeNodes
();
...
...
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