Skip to content

Commit ea5e3ec

Browse files
authored
Merge pull request #261 from yungwine/check-git
fix git config in status and telemetry
2 parents 15d83bc + 3614119 commit ea5e3ec

File tree

3 files changed

+24
-17
lines changed

3 files changed

+24
-17
lines changed

mytoncore/functions.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import subprocess
1111

1212
from mytoncore.mytoncore import MyTonCore
13+
from mytonctrl.utils import fix_git_config
1314
from mytoninstaller.config import GetConfig
1415
from mypylib.mypylib import (
1516
b2mb,
@@ -420,7 +421,9 @@ def Telemetry(local, ton):
420421

421422
# Get git hashes
422423
gitHashes = dict()
423-
gitHashes["mytonctrl"] = get_git_hash("/usr/src/mytonctrl")
424+
mtc_path = "/usr/src/mytonctrl"
425+
local.try_function(fix_git_config, args=[mtc_path])
426+
gitHashes["mytonctrl"] = get_git_hash(mtc_path)
424427
gitHashes["validator"] = GetBinGitHash(
425428
"/usr/bin/ton/validator-engine/validator-engine")
426429
data["gitHashes"] = gitHashes

mytonctrl/mytonctrl.py

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
GetBinGitHash,
4141
)
4242
from mytonctrl.migrate import run_migrations
43-
from mytonctrl.utils import GetItemFromList, timestamp2utcdatetime
43+
from mytonctrl.utils import GetItemFromList, timestamp2utcdatetime, fix_git_config
4444

4545
import sys, getopt, os
4646

@@ -290,21 +290,6 @@ def check_vport(local, ton):
290290
#end define
291291

292292

293-
def fix_git_config(git_path: str):
294-
args = ["git", "status"]
295-
try:
296-
process = subprocess.run(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=git_path, timeout=3)
297-
err = process.stderr.decode("utf-8")
298-
except Exception as e:
299-
err = str(e)
300-
if err:
301-
if 'git config --global --add safe.directory' in err:
302-
args = ["git", "config", "--global", "--add", "safe.directory", git_path]
303-
subprocess.run(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=3)
304-
else:
305-
raise Exception(f'Failed to check git status: {err}')
306-
#end define
307-
308293
def check_git(input_args, default_repo, text):
309294
src_dir = "/usr/src"
310295
git_path = f"{src_dir}/{default_repo}"
@@ -708,6 +693,8 @@ def PrintLocalStatus(local, adnlAddr, validatorIndex, validatorEfficiency, valid
708693
validatorBinGitPath = "/usr/bin/ton/validator-engine/validator-engine"
709694
mtcGitHash = get_git_hash(mtcGitPath, short=True)
710695
validatorGitHash = GetBinGitHash(validatorBinGitPath, short=True)
696+
fix_git_config(mtcGitPath)
697+
fix_git_config(validatorGitPath)
711698
mtcGitBranch = get_git_branch(mtcGitPath)
712699
validatorGitBranch = get_git_branch(validatorGitPath)
713700
mtcGitHash_text = bcolors.yellow_text(mtcGitHash)

mytonctrl/utils.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import subprocess
12
import time
23

34

@@ -12,3 +13,19 @@ def GetItemFromList(data, index):
1213
return data[index]
1314
except:
1415
pass
16+
17+
18+
def fix_git_config(git_path: str):
19+
args = ["git", "status"]
20+
try:
21+
process = subprocess.run(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=git_path, timeout=3)
22+
err = process.stderr.decode("utf-8")
23+
except Exception as e:
24+
err = str(e)
25+
if err:
26+
if 'git config --global --add safe.directory' in err:
27+
args = ["git", "config", "--global", "--add", "safe.directory", git_path]
28+
subprocess.run(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=3)
29+
else:
30+
raise Exception(f'Failed to check git status: {err}')
31+
#end define

0 commit comments

Comments
 (0)