Skip to content

Commit

Permalink
[git-backdate] Don't assume order
Browse files Browse the repository at this point in the history
  • Loading branch information
rixx committed Jul 7, 2023
1 parent c69885c commit 87619fc
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions git-backdate
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,19 @@ def rewrite_history(commits, start, end, dry_run, business_hours, is_rebase):
duration = len(days)
max_commits_per_day = math.ceil(len(commits) / duration)
last_timestamp = None
for index, commit in enumerate(commits):
# if the commit is not the current commit, we need to continue the rebase
commit_count = len(commits)
while commits:
# if the commit is part of our commits of interest, we need to continue the rebase
if is_rebase and not is_equal(commit, "HEAD"):
while not is_equal(commit, "HEAD"):
subprocess.check_call(["git", "rebase", "--continue"])
progress = (index + 1) / len(commits)
progress = len(commits) / commit_count
# first, choose the date
if index == 0 or duration == 0:
if len(commits) == commit_count or duration == 0:
date = start
day_progress = 0
else:
if index == len(commits) - 1:
if len(commits) == 1:
date = end
else:
# select date by index
Expand Down Expand Up @@ -107,6 +108,7 @@ def rewrite_history(commits, start, end, dry_run, business_hours, is_rebase):
["git", "commit", "--amend", "--date", timestamp.isoformat(), commit],
env=dict(os.environ, GIT_COMMITTER_DATE=timestamp.isoformat()),
)
commits.remove(commit)
if is_rebase:
subprocess.check_call(["git", "rebase", "--continue"])

Expand Down

0 comments on commit 87619fc

Please sign in to comment.