Last active
March 17, 2026 11:54
-
-
Save RedFred7/7da53cc193f2faf059f569c656e4e94b to your computer and use it in GitHub Desktop.
Checks if a git commit or PR no exists between two tags (i.e. in a release)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| # frozen_string_literal: true | |
| # Check if a commit hash or PR no (e.g. #1234) exists between two git tags. | |
| # | |
| # Usage: | |
| # ruby git-between.rb <tag1> <tag2> <commit_or_PR> | |
| # | |
| # Examples: | |
| # ruby git-between.rb 2026.03.16-1 2026.03.16-1 8e9dbe631 | |
| # ruby git-between.rb 2026.03.16-1 2026.03.16-1 "#7351" | |
| if ARGV.length != 3 | |
| warn "Usage: #{$PROGRAM_NAME} <tag1> <tag2> <commit_or_string>" | |
| warn "" | |
| warn "Examples:" | |
| warn " #{$PROGRAM_NAME} v1.0.0 v1.1.0 abc123f" | |
| warn " #{$PROGRAM_NAME} v1.0.0 v1.1.0 '#1234'" | |
| exit 1 | |
| end | |
| tag1, tag2, search_term = ARGV | |
| # Verify both tags exist | |
| [tag1, tag2].each do |tag| | |
| unless system("git rev-parse #{tag} >/dev/null 2>&1") | |
| warn "Error: tag '#{tag}' not found" | |
| exit 1 | |
| end | |
| end | |
| # Get the log between the two tags (tag1 exclusive, tag2 inclusive) | |
| log = `git log --oneline --decorate #{tag1}..#{tag2}`.strip | |
| if log.empty? | |
| puts "No commits found between #{tag1} and #{tag2}" | |
| exit 1 | |
| end | |
| matches = log.lines.select { |line| line.include?(search_term) } | |
| if matches.any? | |
| puts "Found '#{search_term}' between #{tag1} and #{tag2}:" | |
| puts "" | |
| matches.each { |line| puts " #{line}" } | |
| else | |
| puts "'#{search_term}' was NOT found between #{tag1} and #{tag2}" | |
| exit 1 | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment