Skip to content

Commit a13582a

Browse files
committed
Merge pull request #3 from codeguard/avoid_commit_in_new_and_old
Avoid putting a commit into both new_log_entries and old_log_entries
2 parents 78a2d69 + a648ec7 commit a13582a

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

lib/git/tail/runner.rb

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,25 @@ def run
5858
def clean_local(branch)
5959
out 2, "#{branch}:"
6060
tip_hash = Git.command 'rev-parse', [branch]
61+
6162
# commits older than and including cutoff
6263
old_log = Git.command 'log', [min_age, '--format=raw', branch]
64+
old_log_entries = old_log.split /(?=commit [0-9a-f]{40})/ # Lookahead assertions FTW
65+
6366
# commits newer than and including cutoff
6467
new_log = Git.command 'log', [max_age, '--format=raw', branch]
68+
new_log_entries = new_log.split /(?=commit [0-9a-f]{40})/
69+
70+
# If the cutoff time is the same as one of the commit times, this
71+
# commit will be in both new_log_entries and old_log_entries. So
72+
# make sure it's only in one.
73+
new_log_entries.pop if new_log_entries.last == old_log_entries.first
6574

66-
if old_log.empty?
75+
if old_log_entries.empty?
6776
out :detail, 2, "No commits prior to cutoff date. Skipping."
68-
elsif new_log.empty?
77+
elsif new_log_entries.empty?
6978
out :detail, 2, "No commits after cutoff date. Skipping."
7079
else
71-
old_log_entries = old_log.split /(?=commit [0-9a-f]{40})/ # Lookahead assertions FTW
72-
new_log_entries = new_log.split /(?=commit [0-9a-f]{40})/
7380
build_commit_map(branch) if replace
7481

7582
out :detail, 4, "Truncating #{old_log_entries.length} commits..."

0 commit comments

Comments
 (0)