emacs使用magit提交到gerrit

从好几年前我就开始一直使用git了,大部分的提交是在命令行下,反
正emacs的shell功能很好用,也从来没有想过安装插件什么的。

我也在用gerrit管理项目,大部分的时候,项目的.git/config的文件
里面都有这样的一段:

      [remote "origin"]
	url = xxxxx
	fetch = +refs/heads/*:refs/remotes/origin/*
	puttykeyfile = 
	push = HEAD:refs/for/master
       

关键是那个push, 可以让我在命令行下直接git push就push到了
refs/for/master分支上了,方便很多。

突然想在emacs中使用下版本管理,我可从来没用过呢。于是查看了下,
magit评价不错,就直接安装配置了下,具体可从https://github.com/magit/magit
看如何安装使用。

但安装完之后发现push的时候默认push的分支是
master:refs/heads/master,没发现特别的需要设置的地方(可能是我没仔
细看),如果不能push到refs/for/master的话,对我而言几乎毫无用途啊。
于是就直接修改下源代码了:

       magit.el | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/magit.el b/magit.el
index ae51473..89a6ad1 100644
--- a/magit.el
+++ b/magit.el
@@ -5422,9 +5422,11 @@ even if `magit-set-upstream-on-push's value is `refuse'."
                                         (eq magit-set-upstream-on-push 'askifnotset)))
                                (yes-or-no-p "Set upstream while pushing? "))))))
             (apply 'magit-run-git-async "push" "-v" push-remote
-                   (if ref-branch
-                       (format "%s:%s" branch ref-branch)
-                     branch)
+                   (cond ((magit-get "remote" push-remote "push")
+                          (magit-get "remote" push-remote "push"))
+                         (t (if ref-branch
+                                (format "%s:%s" branch ref-branch)
+                              branch))) 
                    (if set-upstream-on-push
                        (cons "--set-upstream" magit-custom-options)
                      magit-custom-options))
 
       

修改丑陋,能用就行,反正我对lisp基本上不懂。我的修改可从https://github.com/zeze0556/magit检出。

这样依赖,如果在config中配置了push的相关内容(比如文章一开始的
那个配置格式),就会push到指定的分支上,如果没有配置的话,按照默认
的来。

然后到了gerrit的页面一看,乖乖,中文怎么乱码了,看了下模式,是
在git-commit-mode下,然后编码居然是undeced-xxx的,虽然可以通过在
写完日志之后: C-x ret c utf-8-unix Alt-x git-commit-commit来操作,
但明显太烦人了,不过,幸好这个支持hook,于是就在配置中写下下面的
hookl:

      (defun my-git-commit-hook ()
  (auto-fill-mode)
 (flyspell-mode)
  (set-buffer-file-coding-system 'utf-8-unix))
(add-hook 'git-commit-mode-hook 'my-git-commit-hook)
       

这下子就默认以utf-8-unix的编码提交了,乱码什么的通通散去。

PS: 最近在尝试使用emacs的evil插件,现在稍微习惯些了,vim的快速
移动果然不是盖的,不过总在中文输入法什么的和快捷键上卡壳,有些时
候会和emacs的习惯冲突,慢慢锻炼吧。

发表评论

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据