-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a rake task to install git hooks. Makes it easier to work with …
…plugins as submodules [ci skip]
- Loading branch information
1 parent
734578c
commit f2a4aa3
Showing
1 changed file
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
namespace :git do | ||
desc "Install git submodule hooks and commands for easier development." | ||
task :install_hooks do | ||
postmerge_hook = ".git/hooks/post-merge" | ||
|
||
File.delete postmerge_hook rescue true | ||
File.open(postmerge_hook, 'w') do |f| | ||
f.puts %Q{#!/bin/sh | ||
git submodule update} | ||
end | ||
File.chmod 0755, postmerge_hook | ||
puts "=== Installed post-merge hook.\n (Submodules will now be updated automatically.)" | ||
|
||
submodules = File.open('.gitmodules', 'r').read.split("\n").map {|l| | ||
l[/submodule "(.*)"/, 1] }.compact | ||
|
||
submodules.each do |submodule| | ||
submodule_name = submodule.split("/").last | ||
xpush_cmd = "!git push && cd ../../.. && git add #{submodule} && \ | ||
git commit -m 'Updated #{submodule_name} submodule'" | ||
system("cd #{submodule} && git config alias.xpush \"#{xpush_cmd}\"") | ||
end | ||
|
||
puts "=== Installed `git xpush` command on all submodules.\n (Use it to push the submodule and commit the change to the superproject.)" | ||
end | ||
end | ||
|