diff options
author | Simon Glass <sjg@chromium.org> | 2025-02-27 12:27:30 -0700 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2025-04-10 11:57:49 -0600 |
commit | 774e966f293c552f29a57d9ad7b620e6f334aad9 (patch) | |
tree | 39b069a23f767d732b233097218633b4c209249a /tools/u_boot_pylib/gitutil.py | |
parent | 206ca97fac5bc638b04b712075d8bb4656d79395 (diff) |
patman: Show the base commit and branch
It is helpful to know which commit patches are based on, even if that
commit might not be available to readers. Add a tag for this in the
cover letter.
Also add the local-branch name since that may be useful to the writer.
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'tools/u_boot_pylib/gitutil.py')
-rw-r--r-- | tools/u_boot_pylib/gitutil.py | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/tools/u_boot_pylib/gitutil.py b/tools/u_boot_pylib/gitutil.py index 5e3e98ac9a6..0376bece3e6 100644 --- a/tools/u_boot_pylib/gitutil.py +++ b/tools/u_boot_pylib/gitutil.py @@ -701,13 +701,38 @@ def setup(): .return_code == 0) +def get_hash(spec): + """Get the hash of a commit + + Args: + spec (str): Git commit to show, e.g. 'my-branch~12' + + Returns: + str: Hash of commit + """ + return command.output_one_line('git', 'show', '-s', '--pretty=format:%H', + spec) + + def get_head(): """Get the hash of the current HEAD Returns: Hash of HEAD """ - return command.output_one_line('git', 'show', '-s', '--pretty=format:%H') + return get_hash('HEAD') + + +def get_branch(): + """Get the branch we are currently on + + Return: + str: branch name, or None if none + """ + out = command.output_one_line('git', 'rev-parse', '--abbrev-ref', 'HEAD') + if out == 'HEAD': + return None + return out if __name__ == "__main__": |