gogs迁移hooks路径修改小工具

2 篇文章 0 订阅

问题: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}的替换')

gogs本身提供了hook更新功能,可以登录root账户,在头像处选择管理面板,执行如下图的管理员操作即可

参考文章:

https://blog.csdn.net/qq_33487726/article/details/94429452

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值