-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
git_info: Add get_latest_commit function #57
Implement in all scripts
- Loading branch information
Showing
6 changed files
with
51 additions
and
24 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from pathlib import Path | ||
|
||
|
||
def get_active_branch_name(input_path="."): | ||
|
||
head_dir = Path(input_path) / ".git" / "HEAD" | ||
with head_dir.open("r") as f: | ||
content = f.read().splitlines() | ||
|
||
for line in content: | ||
if line[0:4] == "ref:": | ||
return line.partition("refs/heads/")[2] | ||
|
||
|
||
def get_latest_commit(input_path="."): | ||
|
||
head_dir = Path(input_path) / ".git" / "HEAD" | ||
with head_dir.open("r") as f: | ||
content = f.read().splitlines() | ||
|
||
for line in content: | ||
if line[0:4] == "ref:": | ||
head_path = Path(f".git/{line.partition(' ')[2]}") | ||
with head_path.open('r') as g: | ||
commit = g.read().splitlines() | ||
|
||
return commit[0], commit[0][:7] # full and short hash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters