-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
55 lines (45 loc) · 1.5 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import os
import subprocess
def find_git_repo():
"""
git 저장소의 루트 디렉토리를 찾습니다.
Returns:
str: git 저장소의 루트 디렉토리 경로. 저장소를 찾지 못한 경우 None을 반환합니다.
"""
start_path = os.getcwd()
current_path = start_path
while current_path != os.path.dirname(current_path):
if os.path.isdir(os.path.join(current_path, '.git')):
return current_path
current_path = os.path.dirname(current_path)
return None
def get_git_user_name():
"""
Git 사용자 이름을 가져오는 함수입니다.
Returns:
str: Git 사용자 이름. 가져오는 데 실패한 경우 None을 반환합니다.
"""
try:
result = subprocess.run(
['git', 'config', '--get', 'user.name'],
check=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True
)
user_name = result.stdout.strip()
return user_name
except subprocess.CalledProcessError as e:
print(f"An error occurred while fetching Git user name: {e.stderr}")
return None
if __name__ == "__main__":
repo_path = find_git_repo()
if repo_path:
print(f"Git repository found at: {repo_path}")
else:
print("No Git repository found.")
user_name = get_git_user_name()
if user_name:
print(f"Git user name: {user_name}")
else:
print("Failed to fetch Git user name.")