Skip to content
This repository was archived by the owner on Mar 27, 2026. It is now read-only.

Commit 3fa35d3

Browse files
committed
use latest common commit
1 parent cf5230d commit 3fa35d3

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

gitdiff4llm.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,16 @@ def get_latest_commit():
5555
print(f"Error getting the latest commit: {e}")
5656
sys.exit(1)
5757

58-
# Function to get the latest commit hash from a specified branch
59-
def get_latest_commit_from_branch(branch):
58+
# Function to get the latest common commit between the current branch and base branch
59+
def get_latest_common_commit_with_branch(branch):
6060
try:
6161
result = subprocess.run(
62-
["git", "rev-parse", branch],
62+
["git", "merge-base", "HEAD", branch],
6363
capture_output=True, text=True, check=True, encoding='utf-8', errors='replace'
6464
)
6565
return result.stdout.strip()
6666
except subprocess.CalledProcessError as e:
67-
print(f"Error getting the latest commit from branch '{branch}': {e}")
67+
print(f"Error getting the latest common commit with '{branch}': {e}")
6868
sys.exit(1)
6969

7070
# Main function to generate the combined diff and calculate token count
@@ -102,17 +102,17 @@ def main(commit1, commit2, output_file):
102102
parser.add_argument("-o", "--output_file", required=True, help="The file to output the combined diff.")
103103
parser.add_argument("-c1", "--commit1", help="The first commit hash.")
104104
parser.add_argument("-c2", "--commit2", help="The second commit hash.")
105-
parser.add_argument("-b", "--branch", help="Compare the latest commit on the current branch to the latest commit on another branch (e.g., master).")
105+
parser.add_argument("-b", "--branch", help="Compare the latest commit on the current branch to the latest common commit with another branch (e.g., master).")
106106

107107
args = parser.parse_args()
108108

109109
# Determine the commit hashes
110110
if args.branch:
111-
commit1 = get_latest_commit_from_branch(args.branch)
111+
commit1 = get_latest_common_commit_with_branch(args.branch)
112112
commit2 = get_latest_commit()
113113

114114
# Print the commits being used for the comparison
115-
print(f"Comparing latest commit from branch '{args.branch}' ({commit1[:12]}) with the latest commit on the current branch ({commit2[:12]}).")
115+
print(f"Comparing latest common commit with branch '{args.branch}' ({commit1[:12]}) and the latest commit on the current branch ({commit2[:12]}).")
116116
else:
117117
if not args.commit1 or not args.commit2:
118118
print("You must either provide two commit hashes using --commit1 and --commit2, or use the -b option to compare against another branch.")

0 commit comments

Comments
 (0)