Skip to content

Commit

Permalink
Fixed rebase-all-branches for auto-abort rebasing on conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
ohhmm committed Jan 26, 2025
1 parent 1ebc9c6 commit 3f48e0c
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 2 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/lib
)

fold(
cmake
omnn
OpenMind
)
Expand Down
1 change: 1 addition & 0 deletions cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fold()
1 change: 1 addition & 0 deletions cmake/append-each-line/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exe()
45 changes: 45 additions & 0 deletions cmake/append-each-line/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include <fstream>
#include <iostream>
#include <string>

// defaults used for rebase-all-branches target
#define INPUT_FILE_DEFAULT SRC_DIR "rebase.cmd"
#define SUFFIX_DEFAULT " || \"" GIT_EXECUTABLE_PATH "\" rebase --abort"

int main(int argc, char* argv[]) {
if (argc != 3) {
std::cout << "Usage: " << argv[0] << " <input_file> <suffix>" << std::endl;
std::cout << "Defaults used: <input_file>=" INPUT_FILE_DEFAULT " <suffix>=" SUFFIX_DEFAULT << std::endl;
}

std::string_view input_file = argc == 3 ? argv[1] : INPUT_FILE_DEFAULT;
std::string_view suffix = argc == 3 ? argv[2] : SUFFIX_DEFAULT;

std::ifstream infile(input_file.data());
if (!infile.is_open()) {
std::cerr << "Failed to open file: " << input_file << std::endl;
return 1;
}

std::string output_file = input_file.data();
output_file += ".new";

std::ofstream outfile(output_file);
if (!outfile.is_open()) {
std::cerr << "Failed to create file: " << output_file << std::endl;
return 1;
}

std::string line;
while (std::getline(infile, line)) {
outfile << line << suffix << std::endl;
}

infile.close();
outfile.close();

std::remove(input_file.data());
std::rename(output_file.c_str(), input_file.data());

return 0;
}
1 change: 1 addition & 0 deletions cmake/bins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ function(apply_target_commons this_target)
BOOST_SYSTEM_NO_DEPRECATED
BOOST_ERROR_CODE_HEADER_ONLY
BOOST_COMPUTE_USE_CPP11
-DGIT_EXECUTABLE_PATH="${GIT_EXECUTABLE}"
-DSRC_DIR="${CMAKE_SOURCE_DIR}/"
-D_${dashless}_SRC_DIR="${CMAKE_CURRENT_SOURCE_DIR}/"
-D_${this_target_up}_SRC_DIR="${CMAKE_CURRENT_SOURCE_DIR}/"
Expand Down
7 changes: 5 additions & 2 deletions cmake/gitect.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,18 @@ if(GIT_EXECUTABLE)
set(CMD_ITERATE_BRANCHES "for /f \"usebackq tokens=*\" %b in ( branches.txt ) do ( ${CMD_REBASE_BRANCH} )")
set(CMD_LINE_SUFFIX " ^|^| ${GIT_EXE_CMD} rebase --abort")
add_custom_target(rebase-all-branches
DEPENDS append-each-line

COMMAND ${CMAKE_COMMAND} -E echo "Rebasing all branches onto origin/main"
COMMAND ${GIT_EXECUTABLE} fetch --all || echo git fetch error

COMMAND cmd /c ${CMD_LIST_BRANCHES} > branches.txt
COMMAND type NUL > rebase.cmd
COMMAND cmd /c ( for /f "usebackq tokens=*" %b in ( branches.txt ) do @echo ${CMD_REBASE_BRANCH} ) >> rebase.cmd
COMMAND echo echo rebasing all branches > rebase-or-abort.cmd
COMMAND cmd /c ( ( for /f "usebackq tokens=*" %a in ( rebase.cmd ) do ( echo %a ^|^| ${GIT_EXE_CMD} rebase --abort ) ) >> rebase-or-abort.cmd )
COMMAND cmd /c rebase.cmd
#COMMAND cmd /c ( for /f "usebackq tokens=*" %a in ( rebase.cmd ) do echo %a ^|^| ${GIT_EXE_CMD} rebase --abort ) >> rebase-or-abort.cmd
COMMAND $<TARGET_FILE:append-each-line> rebase.cmd "${CMD_LINE_SUFFIX}"
COMMAND cmd /c rebase.cmd

COMMENT "Rebasing all branches onto origin/main using cmd with improved branch handling."
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
Expand Down

0 comments on commit 3f48e0c

Please sign in to comment.