We have a git repository we have been using for many years. Say, it is a Java - maven project. The project has pom.xml
file that contains important information like
<model_location>path/to/file/model_version</model_location>
I would like to get all model version names from the git repository. Hopefully, I can use GitPython library to do it. I wrote the following code.
repo = Repo('/path/to/repository')
remote_origin = repo.remotes.origin
remote_origin.pull()
path = "path/to/pom.xml"
commits = repo.iter_commits('--all', max_count=1000, paths=path)
for commit in commits:
committer_name = commit.committer.name
timestamp = time.strftime("%F %T", time.localtime(commit.committed_date))
hexsha = commit.hexsha
print(f"{hexsha}\t{committer_name}\t{timestamp}")
The code shows the following result.
afdb36153a53bc45eff52c319a9541498e1c3ce1 committer-1 2020-01-30 09:57:01
e85ca97121384fb34b0fdc1fa04cf78b6c1cd109 committer-1 2020-01-28 13:45:29
61bbf5d706b9dd2caa7b75e0374946ec1b96994c committer-2 2020-01-23 17:44:20
...
c10ead963802053147488b93626ca0b9aab643b1 committer-3 2015-01-06 09:04:33
cf74128281e9374cca8e88a0e23e52f55e37f109 committer-3 2014-12-05 15:01:24
I got a list of commit ids but I have no idea how can I read the model_location
tag in pom.xml
of a specific commit id.
The purpose of this is to know which model was used at a specific period. For example, model version 3.14
had been used between 2014-12-05 15:01:24 and 2015-01-06 09:04:33 and committer-3
checked in the model etc.
I would be really grateful if you could let me know it. I wrote another script that does the same with svn but I am not familiar with git.
Thanks,