@@ -321,6 +321,18 @@ CommitForm::CommitForm(const QString &dir, GitPlugin *plugin, QWidget *parent)
321321 connect (ui->pushButton , &QAbstractButton::clicked, this , &CommitForm::pushImpl);
322322 connect (ui->revertSelectedButton , &QAbstractButton::clicked, this ,
323323 &CommitForm::revertSelectionImpl);
324+ connect (ui->amendCheckbox , &QCheckBox::toggled, this , [this ](bool checked) {
325+ if (checked) {
326+ git->runGit ({" -C" , repoRoot, " log" , " -1" , " --pretty=%B" })
327+ .then (this , [this ](const std::tuple<QString, int > &res) {
328+ auto [msg, exitCode] = res;
329+ if (exitCode == 0 ) {
330+ ui->commitMessage ->setPlainText (msg.trimmed ());
331+ }
332+ });
333+ }
334+ ui->commitButton ->setEnabled (checked || !model->checkedEntries ().isEmpty ());
335+ });
324336 connect (ui->tableView ->selectionModel (), &QItemSelectionModel::selectionChanged, this ,
325337 [this ](const QItemSelection &selected, const QItemSelection &) {
326338 if (selected.indexes ().size () == 0 ) {
@@ -342,7 +354,7 @@ CommitForm::CommitForm(const QString &dir, GitPlugin *plugin, QWidget *parent)
342354
343355 auto hasSelection = !model->checkedEntries ().isEmpty ();
344356 ui->revertSelectedButton ->setEnabled (hasSelection);
345- ui->commitButton ->setEnabled (hasSelection);
357+ ui->commitButton ->setEnabled (hasSelection || ui-> amendCheckbox -> isChecked () );
346358 });
347359 connect (model, &QAbstractItemModel::modelReset, this ,
348360 [this ]() { ui->revertSelectedButton ->setEnabled (false ); });
@@ -543,26 +555,18 @@ void CommitForm::revertSelectionImpl() {
543555
544556void CommitForm::commitImpl () {
545557 auto const &checked = model->checkedEntries ();
546- if (checked.isEmpty ()) {
558+ if (checked.isEmpty () && !ui-> amendCheckbox -> isChecked () ) {
547559 return ;
548560 }
549561
550- auto args = QStringList{" -C" , repoRoot, " add" };
551- for (auto const &c : checked) {
552- args.push_back (c.filename );
553- }
554-
555- ui->gitOutput ->clear ();
556- git->runGit (args).then (this , [this ](const std::tuple<QString, int > &res) {
557- auto [output, exitCode] = res;
558- if (exitCode != 0 ) {
559- ui->gitOutput ->setText (output.trimmed ());
560- qDebug () << QString (" ExitCode=%1, output=%2" ).arg (exitCode).arg (output);
561- return ;
562+ auto doCommit = [this ]() {
563+ auto commitLogFileName = createTempFileWithContent (ui->commitMessage ->toPlainText ());
564+ auto commitArgs = QStringList{" -C" , repoRoot, " commit" };
565+ if (ui->amendCheckbox ->isChecked ()) {
566+ commitArgs << " --amend" ;
562567 }
568+ commitArgs << " -F" << commitLogFileName;
563569
564- auto commitLogFileName = createTempFileWithContent (ui->commitMessage ->toPlainText ());
565- auto commitArgs = QStringList{" -C" , repoRoot, " commit" , " -F" , commitLogFileName};
566570 git->runGit (commitArgs)
567571 .then (this , [this , commitLogFileName](const std::tuple<QString, int > &res2) {
568572 auto [output2, exitCode2] = res2;
@@ -572,10 +576,31 @@ void CommitForm::commitImpl() {
572576 qDebug () << QString (" ExitCode=%1, output=%2" ).arg (exitCode2).arg (output2);
573577 } else {
574578 ui->commitMessage ->clear ();
579+ ui->amendCheckbox ->setChecked (false );
575580 }
576581 updateGitStatus ();
577582 });
578- });
583+ };
584+
585+ if (checked.isEmpty ()) {
586+ doCommit ();
587+ } else {
588+ auto args = QStringList{" -C" , repoRoot, " add" };
589+ for (auto const &c : checked) {
590+ args.push_back (c.filename );
591+ }
592+
593+ ui->gitOutput ->clear ();
594+ git->runGit (args).then (this , [this , doCommit](const std::tuple<QString, int > &res) {
595+ auto [output, exitCode] = res;
596+ if (exitCode != 0 ) {
597+ ui->gitOutput ->setText (output.trimmed ());
598+ qDebug () << QString (" ExitCode=%1, output=%2" ).arg (exitCode).arg (output);
599+ return ;
600+ }
601+ doCommit ();
602+ });
603+ }
579604}
580605
581606void CommitForm::pushImpl () {
@@ -585,6 +610,10 @@ void CommitForm::pushImpl() {
585610 ui->gitOutput ->clear ();
586611
587612 auto args = QStringList{" -C" , repoRoot, " push" };
613+ if (ui->forcePushCheckbox ->isChecked ()) {
614+ args << " --force" ;
615+ }
616+
588617 git->runGit (args).then (this , [this , t](const std::tuple<QString, int > &result) {
589618 auto [output, exitCode] = result;
590619 if (exitCode != 0 ) {
@@ -598,3 +627,5 @@ void CommitForm::pushImpl() {
598627 ui->pushButton ->setEnabled (true );
599628 });
600629};
630+
631+ void CommitForm::setAmend (bool amend) { ui->amendCheckbox ->setChecked (amend); }
0 commit comments