Skip to content

Commit

Permalink
add check if dropped commit is last on branch
Browse files Browse the repository at this point in the history
  • Loading branch information
forgottosave committed Nov 15, 2024
1 parent 85c663f commit a33cec3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/core/OSTreeTUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,9 @@ bool OSTreeTUI::DropLastCommit(const cpplibostree::Commit& commit) {
selectedCommit = 0;
screen.PostEvent(ftxui::Event::AltR);
notificationText =
"Removed commit " + commit.hash.substr(0, 8) + " from branch " + commit.branch;
"Dropped commit " + commit.hash.substr(0, 8) + " from branch " + commit.branch;
} else {
notificationText = "Failed to drop commit";
}
return success;
}
Expand Down
9 changes: 8 additions & 1 deletion src/util/cpplibostree.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "cpplibostree.hpp"

// C++
#include <algorithm>
#include <chrono>
#include <cstdlib>
#include <sstream>
Expand Down Expand Up @@ -338,7 +339,13 @@ bool OSTreeRepo::PromoteCommit(const std::string& hash,

/// TODO This implementation should not rely on the ostree CLI -> change to libostree usage.
bool OSTreeRepo::DropLastCommit(const Commit& commit) {
// TODO check if it is last commit on branch
// check if it is last commit on branch
auto it = std::find_if(
commitList.begin(), commitList.end(),
[&](std::pair<std::string, Commit> c) { return c.second.branch == commit.branch; });
if (it == commitList.end() || commit.hash != it->second.hash) {
return false;
}

// reset head
std::string command = "ostree reset";
Expand Down

0 comments on commit a33cec3

Please sign in to comment.