是否有可能将Git提交挂钩到Textmate上的保存? [英] Is it possible to hook a git commit to the save on Textmate?

查看:132
本文介绍了是否有可能将Git提交挂钩到Textmate上的保存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使我成为Eclipse用户的一个特性是,每次你点击保存时,它的一个副本就会进入Eclipse本地历史记录。然后,您可以对本地历史记录进行区分。



不过,我还是喜欢使用Textmate,因为我听到过这样的好消息。我知道未来的版本有功能请求 ......但我想知道是否有人有发现了一个插件,或者其他一些方法来让这个功能成为Textmate的入口?

谢谢。

更新!

/ strong>
(由于前面的标题没有兴趣,编辑了问题的标题)
我刚才意识到也许这可能是一个解决方案。是否有可能将Textmate保存到git commit中?

解决方案

你想要的是:创建一个新的命令,设置保存为当前文件(此选项位于文本区域上方),输入为整个文档和输出为显示为工具提示。现在将下面的代码复制到文本区域中,并将Command-S分配为命令键绑定。

 #!/ usr / bin / env ruby​​ 
filename = ENV [TM_FILEPATH] .span(/)。$ b $ git add#{ENV [TM_FILEPATH]}`
`git commit -m#{filename}`

每次输入Command -S文件将被保存并提交给(已经存在的)git仓库。如果文件没有改变,那么就不会执行提交,因为git会阻止提交。



下面我扩展了命令来弹出提交对话框消息并给出一个很好的警告,如果没有找到git存储库。你应该能够自己找出其余的。 :)
$ b

 #!/ usr / bin / env ruby​​ 
require ENV [' TM_SUPPORT_PATH'] +'/ lib / ui'

filename = ENV [TM_FILEPATH]。split(/)。last
message = TextMate :: UI.request_string(
:title =>提交#{文件名}的更改,
:prompt =>请输入提交信息以进行更改。


添加=`git add#{ENV [TM_FILEPATH]} 2& 1`
commit =`git commit -m#{message}2& 1`

git_answer = add + commit
除非git_answer.grep(/ fatal /)。empty?
放置请先初始化git存储库!
end


The one feature that has kept me an Eclipse user is that each time you hit save, a copy of it goes into the Eclipse local history. Then you can do a diff on local history.

Still, I'd like to use Textmate since I heard such great things about it. I know there's a feature request for a future version...but I'm wondering if someone has found a plugin, or some other way to get this functionality shoehorned into Textmate now? I know it's a longshot but never hurts to ask.

Thank you.

UPDATE! (Edited the title of the question since the previous title got no interest) I just realized that perhaps this can be a solution. Is it possible to hook the Textmate save into a git commit?

解决方案

What you want is this: Create a new command, set "Save" to "Current File" (this option is above the text area), "Input" to "Entire Document" and "Output" to "Show as Tool Tip". Now copy the code below into the text area and assign Command-S as the commands key-binding.

#!/usr/bin/env ruby
filename = ENV["TM_FILEPATH"].split("/").last
`git add #{ENV["TM_FILEPATH"]}`
`git commit -m "#{filename}"`

Every time you type in Command-S the file will be saved and committed to an (already existing) git repository. If the file wasn't changed, no commit will be done, because git will block the commit.

Below I have extended the command to pop up a dialog for the commit message and to give a nice warning, if no git repository was found. You should be able to figure out the rest yourself. :)

#!/usr/bin/env ruby
require ENV['TM_SUPPORT_PATH'] + '/lib/ui'

filename = ENV["TM_FILEPATH"].split("/").last
message = TextMate::UI.request_string(
    :title => "Commiting changes of #{filename}",
    :prompt => "Please enter the commit message for your changes."
)

add = `git add #{ENV["TM_FILEPATH"]} 2>&1`
commit = `git commit -m "#{message}" 2>&1`

git_answer = add + commit
unless git_answer.grep(/fatal/).empty?
  puts "Please initialize git repository first!"
end

这篇关于是否有可能将Git提交挂钩到Textmate上的保存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆