-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpy_git_logic.py
More file actions
executable file
·28 lines (22 loc) · 855 Bytes
/
Copy pathpy_git_logic.py
File metadata and controls
executable file
·28 lines (22 loc) · 855 Bytes
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
#!/usr/bin/env python3
import os, sys, socket, traceback, json, yaml, getpass
from dulwich.repo import Repo
repo_path = os.path.realpath(os.path.expanduser('~/.myrepo'))
if not os.path.exists(repo_path):
os.mkdir(repo_path)
if not os.path.exists('{}/.git'.format(repo_path)):
repo = Repo.init(repo_path)
else:
repo = Repo(repo_path)
yaml.dump(repo, sys.stdout)
index = repo.open_index()
MSG = f' repo index path={index.path}, index list={list(index)}, '
yaml.dump(MSG, sys.stdout)
f = open(f'{repo_path}/foo', 'wb')
_ = f.write(b"monty1")
f.close()
repo.stage([b"foo"])
print(",".join([f.decode(sys.getfilesystemencoding()) for f in repo.open_index()]))
commit_id = repo.do_commit(b"The first commit") #, committer=getpass.getuser().encode())
print(f' commit_id={commit_id}, repo_head = {repo.head()} ')
#repo = Repo("myrepo")