Skip to content

Commit dcd26a5

Browse files
authored
Show the progress of an ongoing rebase (#74)
* Show rebase step number * Show total number of steps
1 parent 2d5933a commit dcd26a5

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

custom-prompt/custom-prompt.cc

+26-1
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ class GitRepository
198198
void establish_description(void);
199199
void establish_tag(void);
200200
void establish_state(void);
201+
void establish_state_rebasing(void);
201202
void establish_dirty_staged_untracked(void);
202203
// These are static methods because otherwise, their signatures do not
203204
// match the required signatures for use as callback functions.
@@ -310,7 +311,7 @@ void GitRepository::establish_state(void)
310311
case C::GIT_REPOSITORY_STATE_REBASE:
311312
case C::GIT_REPOSITORY_STATE_REBASE_INTERACTIVE:
312313
case C::GIT_REPOSITORY_STATE_REBASE_MERGE:
313-
this->state = "rebasing";
314+
this->establish_state_rebasing();
314315
break;
315316
case C::GIT_REPOSITORY_STATE_REVERT:
316317
case C::GIT_REPOSITORY_STATE_REVERT_SEQUENCE:
@@ -319,6 +320,30 @@ void GitRepository::establish_state(void)
319320
}
320321
}
321322

323+
/**
324+
* Obtain the rebase state of the working tree of the current Git repository.
325+
*/
326+
void GitRepository::establish_state_rebasing(void)
327+
{
328+
this->state = "rebasing";
329+
std::ifstream msgnum_file(this->gitdir / "rebase-merge/msgnum");
330+
if (!msgnum_file.good())
331+
{
332+
return;
333+
}
334+
std::ifstream end_file(this->gitdir / "rebase-merge/end");
335+
if (!end_file.good())
336+
{
337+
return;
338+
}
339+
std::string msgnum_contents, end_contents;
340+
if (!(msgnum_file >> msgnum_contents) || !(end_file >> end_contents))
341+
{
342+
return;
343+
}
344+
this->state += ' ' + msgnum_contents + '/' + end_contents;
345+
}
346+
322347
/**
323348
* Obtain the statuses of the index and working tree of the current Git
324349
* repository.

0 commit comments

Comments
 (0)