From dce978c0fda78da5db1cd7294e4ec503231ccd91 Mon Sep 17 00:00:00 2001 From: Bart Trojanowski Date: Mon, 18 May 2026 13:46:47 -0400 Subject: [PATCH 1/4] nix indent fix --- nix/package.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nix/package.nix b/nix/package.nix index 46874e2..0cc945a 100644 --- a/nix/package.nix +++ b/nix/package.nix @@ -45,7 +45,7 @@ EOF cmakeFlags = [ "-DCMAKE_BUILD_TYPE=Release" - "-DBUILD_TESTING=OFF" + "-DBUILD_TESTING=OFF" ]; buildPhase = '' From 2e76e33e3e8763f30fa1f76042c605ce8308cfe2 Mon Sep 17 00:00:00 2001 From: Bart Trojanowski Date: Mon, 18 May 2026 14:01:32 -0400 Subject: [PATCH 2/4] git wip log - --- src/cmd_log.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/cmd_log.cpp b/src/cmd_log.cpp index ef5d72e..5768c13 100644 --- a/src/cmd_log.cpp +++ b/src/cmd_log.cpp @@ -13,9 +13,10 @@ int LogCmd::run(int argc, char *argv[]) { // ----------------------------------------------------------------------- // 1. Parse arguments // ----------------------------------------------------------------------- - bool pretty = false; - bool stat = false; + bool pretty = false; + bool stat = false; bool reflog_mode = false; + size_t limit = 0; std::vector files; std::vector args; @@ -35,13 +36,25 @@ int LogCmd::run(int argc, char *argv[]) { } else if (a == "--reflog" || a == "-r") { reflog_mode = true; } else if (a == "--help" || a == "-h") { - std::println("Usage: git-wip log [--pretty|-p] [--stat|-s] [--reflog|-r] [-- ...]\n"); + std::println("Usage: git-wip log [-] [--pretty|-p] [--stat|-s] [--reflog|-r] [-- ...]\n"); // - # + std::println(" - # number of entries to display"); std::println(" -p, --pretty # use pretty oneline log (default full log)"); std::println(" -s, --stat # show file changes in log"); std::println(" -r, --reflog # invoke reflog (shows historical entries)"); std::println(" ... # filter on changes to specific file(s)\n"); return 0; + } else if (a[0] == '-' && std::all_of(a.begin()+1, a.end(), [](char ch) { return std::isdigit(ch); })) { + + long value = 0; + auto [ptr,ec] = std::from_chars(a.data()+1, a.data() + a.size(), value); + if (ec == std::errc{} && ptr == a.data() + a.size() && value > 0) { + limit = value; + } else { + spdlog::error("could not parse log limit from '{}'", a); + return 1; + } + } else if (!a.empty() && a[0] == '-') { spdlog::error("git-wip log: unknown option '{}'", a); return 1; @@ -133,6 +146,7 @@ int LogCmd::run(int argc, char *argv[]) { spdlog::debug("log: stop={}", stop_arg); std::string cmd = "git log"; + if (limit) cmd += fmt::format(" -{}", limit); if (pretty) cmd += " --graph" + pretty_fmt; if (stat) cmd += " --stat"; for (const auto &f : files) cmd += " -- " + f; From fb29767e42964268aedb8846e04aecc18d5952af Mon Sep 17 00:00:00 2001 From: Bart Trojanowski Date: Mon, 18 May 2026 14:08:40 -0400 Subject: [PATCH 3/4] git wip log tests --- AGENTS.md | 3 +- test/cli/CMakeLists.txt | 2 +- test/cli/test_log.sh | 125 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 128 insertions(+), 2 deletions(-) create mode 100755 test/cli/test_log.sh diff --git a/AGENTS.md b/AGENTS.md index f0dc359..31cef02 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -4,7 +4,7 @@ - Use c++23 best practices. Use CamelCase for classes, use snake_case for method names, variable names, etc. Use #pragma once in headers. Use m_ prefix for member variables. - use manual arg parsing, use spdlog for debug logging (set `WIP_DEBUG=1` to see debug), use libgit2 for git functionality -- build with `make`, test with `make test` +- build with `make BUILD=build-agent`, test with `make BUILD=build-agent test` — use `BUILD=build-agent` to isolate agent builds from user's default `build/` directory - manage/install dependencies with `dependencies.sh` script - unit tests go into `test/unit/test_*.cpp` - CLI integration tests go into `test/cli/test_*.sh` — source `test/cli/lib.sh`, must be executable @@ -229,6 +229,7 @@ test/cli/ test_status.sh # status command tests test_status2.sh # status after work-branch advance test_save_file.sh # save with explicit file arguments + test_log.sh # log command tests CMakeLists.txt # registers each test_*.sh with ctest ``` diff --git a/test/cli/CMakeLists.txt b/test/cli/CMakeLists.txt index a4ea8ad..58b614a 100644 --- a/test/cli/CMakeLists.txt +++ b/test/cli/CMakeLists.txt @@ -9,7 +9,7 @@ set(LEGACY_TEST_TREE "${CMAKE_CURRENT_BINARY_DIR}/test-artifacts") set(GIT_WIP_BIN "$") -foreach(TEST_NAME IN ITEMS test_legacy test_spaces test_status test_status2 test_status_ref test_save_file test_save_subdir test_list test_delete test_help) +foreach(TEST_NAME IN ITEMS test_legacy test_spaces test_status test_status2 test_status_ref test_save_file test_save_subdir test_list test_delete test_help test_log) add_test( NAME "cli/${TEST_NAME}" COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/${TEST_NAME}.sh" diff --git a/test/cli/test_log.sh b/test/cli/test_log.sh new file mode 100755 index 0000000..9a28b73 --- /dev/null +++ b/test/cli/test_log.sh @@ -0,0 +1,125 @@ +#!/usr/bin/env bash +source "$(dirname "$0")/lib.sh" + +create_test_repo +RUN git config user.email "test@example.com" +RUN git config user.name "Test User" + +RUN "echo v1 >file.txt" +RUN git add file.txt +RUN git commit -m initial + +# ------------------------------------------------------------------------- +# no wip branch yet — log should report error + +_RUN "$GIT_WIP" log +EXP_grep "has no WIP commits" + +# ------------------------------------------------------------------------- +# create 3 wip commits with distinct file changes + +RUN "echo v2 >file.txt" +RUN "$GIT_WIP" save "\"WIP one\"" + +RUN "echo v3 >file.txt" +RUN "$GIT_WIP" save "\"WIP two\"" + +RUN "echo v4 >file.txt" +RUN "$GIT_WIP" save "\"WIP three\"" + +# ------------------------------------------------------------------------- +# log (no flags) — default full log format + +RUN "$GIT_WIP" log +EXP_grep "^commit " +EXP_grep "WIP three" +EXP_grep "WIP two" +EXP_grep "WIP one" + +# ------------------------------------------------------------------------- +# log -p / --pretty — compact oneline graph format + +RUN "$GIT_WIP" log -p +EXP_grep "WIP three" +EXP_grep "WIP two" +EXP_grep "WIP one" +# pretty format includes color codes and relative time +EXP_grep "ago" + +RUN "$GIT_WIP" log --pretty +EXP_grep "WIP three" +EXP_grep "ago" + +# ------------------------------------------------------------------------- +# log -s / --stat — shows file changes + +RUN "$GIT_WIP" log -s +EXP_grep "^commit " +EXP_grep "WIP three" +EXP_grep "file.txt" +EXP_grep "changed" + +RUN "$GIT_WIP" log --stat +EXP_grep "file.txt" +EXP_grep "changed" + +# ------------------------------------------------------------------------- +# log -p -s — both pretty and stat + +RUN "$GIT_WIP" log -p -s +EXP_grep "WIP three" +EXP_grep "file.txt" +EXP_grep "changed" + +# ------------------------------------------------------------------------- +# log - — limit number of entries + +RUN "$GIT_WIP" log -1 +EXP_grep "WIP three" +EXP_grep -v "WIP two" +EXP_grep -v "WIP one" + +RUN "$GIT_WIP" log -2 +EXP_grep "WIP three" +EXP_grep "WIP two" +EXP_grep -v "WIP one" + +# ------------------------------------------------------------------------- +# log --reflog / -r — shows reflog entries + +RUN "$GIT_WIP" log -r +EXP_grep "refs/wip/master" +EXP_grep "git-wip:" + +RUN "$GIT_WIP" log --reflog +EXP_grep "refs/wip/master" + +# ------------------------------------------------------------------------- +# log after work branch advances — wip log resets to new base + +RUN git add file.txt +RUN git commit -m "\"real commit\"" + +RUN "echo v5 >file.txt" +RUN "$GIT_WIP" save "\"WIP after commit\"" + +# now log should show only the new wip commit, not the old ones +RUN "$GIT_WIP" log +EXP_grep "WIP after commit" +EXP_grep -v "WIP three" +EXP_grep -v "WIP two" +EXP_grep -v "WIP one" + +# ------------------------------------------------------------------------- +# log -h / --help — shows usage + +RUN "$GIT_WIP" log -h +EXP_grep "Usage:" +EXP_grep "pretty" +EXP_grep "stat" +EXP_grep "reflog" + +RUN "$GIT_WIP" log --help +EXP_grep "Usage:" + +echo "OK: $TEST_NAME" From 8771130d5333139e53f7301c8fef9d32ebcdb111 Mon Sep 17 00:00:00 2001 From: Bart Trojanowski Date: Mon, 18 May 2026 14:11:07 -0400 Subject: [PATCH 4/4] .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 00ab863..0d12393 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ *~ build/ +build-*/ .cache/ .opencode/ /git-wip