We are using jgit
to store versions for some internal files and i would like to allow only a limited number of versions per file. Currently I can add an unlimited number of commits per file using:
git.add()
.addFilepattern(fileName + ".yaml")
.call();
git.commit()
.setMessage(comment)
.setAuthor((String)context.get("userName"),(String)context.get("userName")+"@xxx.ch")
.call();
I would like to check if the number of git versions per file is greater of n and in that case squash
the n-version
and n+1 version
or just delete the n+1 version
. How can I check in jGit if the number of versions for a specific file in the repo is greater of n and squash two versions or the delete the n+1 version
? Is there maybe a better way to do this?
UPDATE:
Say I allow 5 versions for each file in the git repo and I have the following entries in the git reflog
:
A-----B------C------D------E------F------G------H------I
The specific file has the following git log
entires:
B-----C------E------F------G------H
I can envision two options: One option: "squash" commits G and H to Z. Second option: "delete" commit H
I am working only in one branch (master) on a local machine. I reviewed the answer to this question but I am still not sure how can I do this using `jGit.