問題:Windows下gogs遷移後,push時報錯remote: hooks/pre-receive路徑問題
解決:在gogs-repositories倉庫中找到每個用戶每個工程的hooks文件夾,修改post-receive
pre-receive
update
三個腳本中的調用路徑。
小工具:批量修改路徑
#encoding=utf8
import os
if __name__ == '__main__':
root_path = 'gogs/gogs-repositories'
ori_exe_path, dst_exe_path = 'gogs', 'gogs/gogs'
ori_conf_path, dst_conf_path = 'conf/app.ini', 'gogs/conf/app.ini'
user_dirs = os.listdir(root_path)
for user_dir in user_dirs:
user_root_path = os.path.join(root_path, user_dir)
if os.path.isdir(user_root_path):
pro_dirs = os.listdir(user_root_path)
for pro_dir in pro_dirs:
pro_root_dir = os.path.join(user_root_path, pro_dir)
if os.path.isdir(pro_root_dir):
if os.path.exists(os.path.join(pro_root_dir,'hooks')):
file_arr = ['pre-receive','post-receive','update']
for file in file_arr:
f = open(os.path.join(pro_root_dir, 'hooks', file), 'r')
text = f.read()
text = text.replace(ori_exe_path, dst_exe_path)
text = text.replace(ori_conf_path, dst_conf_path)
f.close()
f = open(os.path.join(pro_root_dir, 'hooks', file), 'w')
f.write(text)
print(f'已完成{pro_root_dir}的替換')
參考文章: