-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
43 additions
and
30 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
from os import path | ||
|
||
__version__ = "0.16.1" | ||
__version__ = "0.16.2" | ||
|
||
co_path = path.dirname(__file__) | ||
|
||
|
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 |
---|---|---|
@@ -1,27 +1,39 @@ | ||
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 | ||
from os.path import dirname, basename, exists, join | ||
|
||
# Get git root | ||
git_root = dirname(__file__.replace(f'/{basename(__file__)}', '')) | ||
|
||
|
||
def get_active_branch_name(input_path=git_root): | ||
if exists(join(input_path, ".git", "HEAD")): | ||
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] | ||
else: | ||
return f"HEAD detached : {content[0]}" | ||
else: | ||
return '.git structure does not exist' | ||
|
||
|
||
def get_latest_commit(input_path=git_root): | ||
|
||
if exists(join(input_path, ".git", "HEAD")): | ||
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(join(input_path, f".git/{line.partition(' ')[2]}")) | ||
with head_path.open('r') as g: | ||
commit = g.read().splitlines() | ||
else: | ||
commit = content | ||
return commit[0], commit[0][:7] # full and short hash | ||
else: | ||
return '.git structure does not exist', '' |
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