diff --git a/app.py b/app.py
index 0c5d650..2d7420a 100644
--- a/app.py
+++ b/app.py
@app.route("/<repo_name>/diff")
def repo_diff(repo_name):
- id1 = request.args.get('id1', 'HEAD')
- id2 = request.args.get('id2', 'HEAD')
+ id1 = request.args.get('id1')
+ id2 = request.args.get('id2')
diff = get_diff(f"{repo_path}/{repo_name}", id1=id1, id2=id2)
return render_template("diff.html", diff=diff)
diff --git a/git/diff.py b/git/diff.py
index 5e5b75c..ea1998c 100644
--- a/git/diff.py
+++ b/git/diff.py
import pygit2 as git
# compares two refs and return diff stats per file and full patch
-def get_diff(path, id1="HEAD", id2="HEAD"):
+def get_diff(path, id1, id2):
repo = git.Repository(path)
- ref_one = repo.revparse_single(id1)
- ref_two = repo.revparse_single(id2)
+ if not id1:
+ id1 = 'HEAD~1'
+ if not id2:
+ id2 = 'HEAD'
+ ref_one = repo.revparse_single(id1) # older
+ ref_two = repo.revparse_single(id2) # newer
diff = repo.diff(ref_one, ref_two)
# TODO: context_lines, interhunk_lines, etc as options
return {
'patch': diff.patch,
- 'files': changed_files
+ 'files': changed_files,
+ 'ref1_id': str(ref_one.id),
+ 'ref2_id': str(ref_two.id),
+ 'ref1': id1,
+ 'ref2': id2
}
diff --git a/templates/diff.html b/templates/diff.html
index a1da9de..88388b5 100644
--- a/templates/diff.html
+++ b/templates/diff.html
{% block content %}
+<h1>Diff between {{ diff.ref1 }} ({{ diff.ref1_id[:7] }}) and {{ diff.ref2 }} ({{ diff.ref2_id[:7] }})</h1>
+
<h2>Changed Files</h2>
<ul>
{% for file in diff.files %}