Skip to content

Commit

Permalink
fix(*): improve correctness of branch namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
WangYihang committed Jul 27, 2022
1 parent 5705463 commit 3afe46d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
12 changes: 5 additions & 7 deletions GitHacker/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import threading


__version__ = "1.1.3"
__version__ = "1.1.4"

coloredlogs.install(fmt='%(asctime)s %(levelname)s %(message)s')

Expand Down Expand Up @@ -259,26 +259,24 @@ def add_head_file_tasks(self):
def parse_current_branch_name(self):
url = f"{self.url}.git/HEAD"
response = requests.get(url, verify=self.verify)
# TODO: [a-zA-Z\d]+ is not sufficient for matching a branch name [1,2].
# TODO: [a-zA-Z\d_-]+ is not sufficient for matching a branch name [1,2].
# For example, a branch which named as `issue-10` cannot be matched.
# References
# [1] https://stackoverflow.com/a/67151923
# [2] https://github.com/git/git/blob/v2.37.1/refs.c#L38-L57
branch_names = re.findall(r'ref: refs/heads/([a-zA-Z\d]+)', response.text)
branch_names = re.findall(r'ref: refs/heads/([a-zA-Z\d_-]+)', response.text)
assert len(branch_names) == 1
return branch_names

def parse_logged_branch_names(self):
url = f"{self.url}.git/logs/HEAD"
response = requests.get(url, verify=self.verify)
# TODO: [a-zA-Z\d]+ is not sufficient for matching a branch name [1,2].
# TODO: [a-zA-Z\d_-]+ is not sufficient for matching a branch name [1,2].
# For example, a branch which named as `issue-10` cannot be matched.
# References
# [1] https://stackoverflow.com/a/67151923
# [2] https://github.com/git/git/blob/v2.37.1/refs.c#L38-L57
print(response.text)

branch_names = re.findall(r'checkout: moving from ([a-zA-Z\d]+) to ([a-zA-Z\d]+)', response.text)
branch_names = re.findall(r'checkout: moving from ([a-zA-Z\d_-]+) to ([a-zA-Z\d_-]+)', response.text)
branch_names_uniq = list(set([i[0] for i in branch_names] + [i[1] for i in branch_names]))
return branch_names_uniq

Expand Down
1 change: 0 additions & 1 deletion utils/gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ def generate_random_commits(repo, root, n, prefix):
for i in range(n):
logging.debug(f"Creating the {i+1} th of {n} random commits")
files = generate_random_files(repo, root, random.randint(2, 16), prefix=f"{prefix}_commit")
print(files)
repo.index.add(files)
repo.index.commit(f"create {files}")

Expand Down

0 comments on commit 3afe46d

Please sign in to comment.