{"id":20662427,"url":"https://github.com/ovinc/gittools","last_synced_at":"2026-05-01T12:32:17.086Z","repository":{"id":57434844,"uuid":"328789478","full_name":"ovinc/gittools","owner":"ovinc","description":"Tools to get git information on files/paths and python modules, based on gitpython.","archived":false,"fork":false,"pushed_at":"2025-10-28T08:50:13.000Z","size":34,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-28T10:24:49.910Z","etag":null,"topics":["git","python","python3"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ovinc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-01-11T20:56:20.000Z","updated_at":"2025-10-28T08:50:17.000Z","dependencies_parsed_at":"2022-09-04T15:32:25.885Z","dependency_job_id":null,"html_url":"https://github.com/ovinc/gittools","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/ovinc/gittools","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ovinc%2Fgittools","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ovinc%2Fgittools/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ovinc%2Fgittools/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ovinc%2Fgittools/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ovinc","download_url":"https://codeload.github.com/ovinc/gittools/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ovinc%2Fgittools/sbom","scorecard":{"id":715517,"data":{"date":"2025-08-11","repo":{"name":"github.com/ovinc/gittools","commit":"70b6e22964d73f9d29950109292ee869c0c01edb"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3,"checks":[{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Code-Review","score":0,"reason":"Found 0/22 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: BSD 3-Clause \"New\" or \"Revised\" License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}}]},"last_synced_at":"2025-08-22T09:30:28.308Z","repository_id":57434844,"created_at":"2025-08-22T09:30:28.309Z","updated_at":"2025-08-22T09:30:28.309Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32497810,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-30T13:12:12.517Z","status":"online","status_checked_at":"2026-05-01T02:00:05.856Z","response_time":64,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["git","python","python3"],"created_at":"2024-11-16T19:14:06.813Z","updated_at":"2026-05-01T12:32:17.072Z","avatar_url":"https://github.com/ovinc.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# About\n\nTools for getting information about git repositories in python, based on *gitpython*; *gittools* provides functions to get quick commit information of paths / files:\n- `current_commit_hash()` (return *str* of latest commit)\n- `path_status()` (return *dict* with more info, e.g. tags, dirty or not, etc.)\n\nThere are also functions targeted for use on python packages and modules that are within a git repository (e.g. following editable install from git clone):\n- `module_status()`: similar to *path_status()* but with a python package or module as an input instead of a path\n- `check_modules()`: check the status of a collection of python modules/packages using module_status()\n- `save_metadata()`: save git information and any other metadata provided as input into a JSON file.\n\nOther functions include `repo_tags()` and `path_in_tree()` (see below).\n\nSee docstrings and information below for more details.\n\n\n# Install\n\n```bash\npip install gittools\n```\n\n# Contents\n\nSee help / docstrings of functions for details, and **Examples** section below.\n\n## General functions\n\n```python\ncurrent_commit_hash(\n    path='.',\n    checkdirty=True,\n    checktree=True,\n)\n```\ncommit hash (str) of HEAD commit of repository where path belongs; if True, `checkdirty` and `checktree` raise exceptions if repo is dirty and if path does not belong to repo's tree, respectively.\n\n```python\npath_status(path='.')\n```\nSimilar to `current_commit_hash()` but does not raise exceptions. Instead, returns git status (commit hash, dirty or clean, tag if there is one) as a dictionary.\n\n```python\nmodule_status(module, nogit_ok=True)\n```\nSimilar to `path_status()` but takes a python module or python package as input.\nIf `nogit_ok` is set to `False`, the function will raise an error when the module is not versioned by git.\nIf `nogit_ok` is set to `True`, module status will indicate version info if available.\n\n\n## Functions for collections of modules and metadata\n\n```python\ncheck_modules(\n    modules,\n    dirty_warning=False,\n    dirty_ok=False,\n    notag_warning=False,\n    nogit_ok=False,\n    nogit_warning=False,\n)\n```\nGet version information for a collection of modules.\nData is returned as a dict of dicts where the keys are module names and the nested dicts correspond to dicts returned by `path_status()`.\n\nThere is a `nogit_ok` option to avoid raising an error if one or several modules are not in a git repository.\nIn this case, the returned information of the module indicates that the module is not in a git repo and uses the module version number as a tag.\nSimilarly, if `dirty_ok` is set to True, no `DirtyRepo` exception is thrown if the modules have a dirty repository.\n\nOther options are to print warnings when:\n- the repo is dirty, i.e. uncommitted (`dirty_warning`),\n- it is missing a tag at the current commit (`notag_warning`),\n- one or more modules are not in a git repo (`nogit_warning`).\n\n\n```python\nsave_metadata(\n    file,\n    info=None,\n    module=None,\n    dirty_warning=False,\n    dirty_ok=False,\n    notag_warning=False,\n    nogit_ok=False,\n    nogit_warning=False,\n):\n```\nSave metadata (`infos` dictionary), current time, and git module info. The `module`, `dirty_warning`, `notag_warning`, `nogit_ok` and `nogit_warning` parameters are the same as for `module_status()`.\n\n\n## Miscellaneous functions\n\n\n- `repo_tags(path='.')`: lists all tags in repository the path belongs to, as a {'commit hash': 'tag name'} dictionary (both keys and values are strings).\n\n- `path_in_tree(path, commit)`: used by *current_commit_hash*; returns True if path belongs to the commit's working tree (or is the root directory of repo), else False.\n\n\nExceptions\n----------\n\nThe `checkdirty` and `checktree` options raise custom exceptions: `DirtyRepo` and `NotInTree`, respectively.\n\n\n# Examples\n\n```python\n\u003e\u003e\u003e from gittools import current_commit_hash, repo_tags\n\n\u003e\u003e\u003e current_commit_hash()  # Most recent commit of the current working directory\n'1f37588eb5aadf802274fae74bc4abb77d9d8004'\n\n# Other possibilities\n\u003e\u003e\u003e current_commit_hash(checkdirty=False) # same, but avoid raising DirtyRepo\n\u003e\u003e\u003e current_commit_hash('gitrepos/repo1/foo.py') # same, but specify path/file\n\n# Note that the previous example will raise an exception if the file is not\n# tracked in a git repository. To silence the exception and see the most\n# recent commit hash of the closest git repository in a parent directory:\n\u003e\u003e\u003e current_commit_hash('Test/untracked_file.pyc', checktree=False)\n\n# List all tags of repo:\n\u003e\u003e\u003e repo_tags()  # current directory, but also possible to specify path\n{'1f37588eb5aadf802274fae74bc4abb77d9d8004': 'v1.1.8',\n 'b5173941c9cceebb786b0c046c67ea505786d820': 'v1.1.9'}\n```\n\nIt can be easier to use higher level functions to get hash name, clean/dirty status, and tag (if it exists):\n```python\n\u003e\u003e\u003e from gittools import path_status, module_status\n\n\u003e\u003e\u003e path_status()  # current working directory (also possible to specify path)\n{'hash': '1f37588eb5aadf802274fae74bc4abb77d9d8004',\n 'status': 'clean',\n 'tag': 'v1.1.8'}\n\n\u003e\u003e\u003e import mypackage1  # module with clean repo and tag at current commit\n\u003e\u003e\u003e module_status(mypackage1)\n{'hash': '1f37588eb5aadf802274fae74bc4abb77d9d8004',\n 'status': 'clean',\n 'tag': 'v1.1.8'}\n\n\u003e\u003e\u003e import mypackage2  # this package has uncommitted changes and no tags\n\u003e\u003e\u003e module_status(mypackage2)\n{'hash': '8a0305e6c4e7a57ad7befee703c4905aa15eab23',\n'status': 'dirty'}\n\n\u003e\u003e\u003e check_modules(\n    [mypackage1, mypackage2],\n    dirty_ok=True,\n    dirty_warning=True,\n)\nWarning: the following modules have dirty git repositories: mypackage2\n{'mypackage1': {'hash': '1f37588eb5aadf802274fae74bc4abb77d9d8004',\n                'status': 'clean',\n                'tag': 'v1.1.8'},\n 'mypackage2': {'hash': '8a0305e6c4e7a57ad7befee703c4905aa15eab23',\n                'status': 'dirty'}}\n\n# mypackage3 not a git repo\n\u003e\u003e\u003e check_modules(\n    [mypackage1, mypackage2, mypackage3],\n    dirty_ok=True,\n    nogit_ok=True,\n)\n{'mypackage1': {'hash': '1f37588eb5aadf802274fae74bc4abb77d9d8004',\n                'status': 'clean',\n                'tag': 'v1.1.8'},\n 'mypackage2': {'hash': '8a0305e6c4e7a57ad7befee703c4905aa15eab23',\n                'status': 'dirty'},\n 'mypackage3': {'status': 'not a git repository',\n                'tag': 'v1.3.2'}}\n```\n\nSave metadata with current time and git info (from `module_status()`)\n```python\n\u003e\u003e\u003e import gittools, oclock, numpy\n\u003e\u003e\u003e from gittools import save_metadata\n\u003e\u003e\u003e modules = gittools, oclock\n\u003e\u003e\u003e parameters = {'temperature': 25, 'pressure': 2338}\n\u003e\u003e\u003e save_metadata('metadata.json', info=parameters, modules=modules, dirty_ok=True, nogit_ok=True)\n\n# Writes a .json file with the following info:\n{\n    \"temperature\": 25,\n    \"pressure\": 2338,\n    \"time (utc)\": \"2020-12-03 21:33:17\",\n    \"code version\": {\n        \"gittools\": {\n            \"hash\": \"12f2ceb3c5fffcc31e422474485e2481890a8094\",\n            \"status\": \"dirty\",\n            \"tag\": \"v0.3.1\"\n        },\n        \"oclock\": {\n            \"hash\": \"826aa76e5096680805eb43fb22a80ccc3b282015\",\n            \"status\": \"clean\",\n            \"tag\": \"v1.0.1\"\n        }\n        \"numpy\": {\n            \"status\": \"not a git repository\",\n            \"tag\": \"v1.19.2\"\n        }\n    }\n}\n```\n\n\n# Requirements / dependencies\n\n### Python\n\n- Python \u003e= 3.6\n\n### Python packages\n\n(installed automatically by pip if necessary)\n\n- gitpython (https://gitpython.readthedocs.io)\n- importlib-metadata\n\n### Other\n\n- git (see gitpython requirements for git minimal version)\n\n\n# Author\n\nOlivier Vincent (ovinc.py@gmail.com)\n\n# License\n\n3-Clause BSD (see *LICENSE* file)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fovinc%2Fgittools","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fovinc%2Fgittools","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fovinc%2Fgittools/lists"}