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

Commit 9337519

Browse files
committed
output to tempfile
1 parent 3fa35d3 commit 9337519

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

gitdiff4llm.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import json
55
import tiktoken
66
import argparse
7+
import tempfile
78

89
# Tokenizer function using OpenAI's tiktoken for LLMs (GPT-3/4)
910
def count_tokens(text, model):
@@ -99,7 +100,7 @@ def main(commit1, commit2, output_file):
99100
if __name__ == "__main__":
100101
# Set up argument parser
101102
parser = argparse.ArgumentParser(description="Run git diff between two commits and analyze with LLM.")
102-
parser.add_argument("-o", "--output_file", required=True, help="The file to output the combined diff.")
103+
parser.add_argument("-o", "--output_file", help="The file to output the combined diff.")
103104
parser.add_argument("-c1", "--commit1", help="The first commit hash.")
104105
parser.add_argument("-c2", "--commit2", help="The second commit hash.")
105106
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).")
@@ -120,7 +121,13 @@ def main(commit1, commit2, output_file):
120121
commit1 = args.commit1
121122
commit2 = args.commit2
122123

123-
output_file = args.output_file
124+
# Set output file or default to the user's temporary directory
125+
if args.output_file:
126+
output_file = args.output_file
127+
else:
128+
temp_dir = tempfile.gettempdir()
129+
output_file = os.path.join(temp_dir, "gitdiff_output.txt")
130+
print(f"No output file specified. Using temporary directory: {output_file}")
124131

125132
# Make sure the output directory exists
126133
os.makedirs(os.path.dirname(output_file), exist_ok=True)

0 commit comments

Comments
 (0)