rebase: identify a rebase that has not started In `git_rebase_operation_current()`, indicate when a rebase has not started (with `GIT_REBASE_NO_OPERATION`) rather than conflating that with the first operation being in-progress.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
diff --git a/CHANGELOG.md b/CHANGELOG.md
index be8e924..69c6991 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -101,6 +101,10 @@ v0.22 + 1
* `git_note_default_ref()` now uses a `git_buf` to return the string,
as the string is otherwise not guaranteed to stay allocated.
+* `git_rebase_operation_current()` will return `GIT_REBASE_NO_OPERATION`
+ if it is called immediately after creating a rebase session but before
+ you have applied the first patch.
+
v0.22
------
diff --git a/include/git2/rebase.h b/include/git2/rebase.h
index 58b66b7..3d8d180 100644
--- a/include/git2/rebase.h
+++ b/include/git2/rebase.h
@@ -89,6 +89,9 @@ typedef enum {
#define GIT_REBASE_OPTIONS_VERSION 1
#define GIT_REBASE_OPTIONS_INIT {GIT_REBASE_OPTIONS_VERSION}
+/** Indicates that a rebase operation is not (yet) in progress. */
+#define GIT_REBASE_NO_OPERATION SIZE_MAX
+
/**
* A rebase operation
*
@@ -170,6 +173,9 @@ GIT_EXTERN(size_t) git_rebase_operation_entrycount(git_rebase *rebase);
/**
* Gets the index of the rebase operation that is currently being applied.
+ * If the first operation has not yet been applied (because you have
+ * called `init` but not yet `next`) then this returns
+ * `GIT_REBASE_NO_OPERATION`.
*
* @param rebase The in-progress rebase
* @return The index of the rebase operation currently being applied.
diff --git a/src/rebase.c b/src/rebase.c
index eb25d4c..3bc10f4 100644
--- a/src/rebase.c
+++ b/src/rebase.c
@@ -1148,7 +1148,7 @@ size_t git_rebase_operation_current(git_rebase *rebase)
{
assert(rebase);
- return rebase->current;
+ return rebase->started ? rebase->current : GIT_REBASE_NO_OPERATION;
}
git_rebase_operation *git_rebase_operation_byindex(git_rebase *rebase, size_t idx)
diff --git a/tests/rebase/iterator.c b/tests/rebase/iterator.c
index 2cff82c..23272d5 100644
--- a/tests/rebase/iterator.c
+++ b/tests/rebase/iterator.c
@@ -65,7 +65,7 @@ void test_rebase_iterator__iterates(void)
cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL));
- test_operations(rebase, 0);
+ test_operations(rebase, GIT_REBASE_NO_OPERATION);
git_rebase_free(rebase);
cl_git_pass(git_rebase_open(&rebase, repo));