gary (owner)

Revisions

gist: 25348 Download_button fork
public
Public Clone URL: git://gist.github.com/25348.git
Embed All Files: show embed
subtree.sake #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# Git Sub-Trees Sake Tasks
# http://rubyurl.com/BwnY < - Read about the technique vs submodules
#
# This works super good with Rails plugins or when you are actively working
# on two related projects.
#
# Add these tasks with:
# sake -i http://pastie.caboo.se/213492.rb
#
# Example Usage:
#
# sake git:subtree:remote
# Git Repo Url? git://github.com/mislav/will_paginate.git
# Remote Name? vendor/plugins/will_paginate
# sake git:subtree:merge
# Branch? will_paginate/tags/2.2.2
# Destination? vendor/plugins/will_paginate
# git commit
#
# From time to time update your remotes:
# git remote update
# -or-
# git fetch vendor/plugins/will_paginate
#
# View diffs:
#
# sake git:subtree:diff
# Branch? vendor/plugins/will_paginate/tags/2.2.3
#
# Merge in updates:
#
# sake git:subtree:update
# Branch? vendor/plugins/will_paginate/tags/2.2.3
# git commit
 
desc 'Add an external project as a remote'
task 'git:subtree:remote' do
  require "readline"
  url = begin
    print "Git Repo Url? "
    Readline.readline.chomp
  end
  name = begin
    print "Remote Name? "
    Readline.readline.chomp
  end
  `git remote add #{name} #{url}`
  `git config remote.#{name}.fetch refs/heads/*:refs/remotes/#{name}/*`
  `git config --add remote.#{name}.fetch refs/tags/*:refs/remotes/#{name}/tags/*`
  `git config remote.#{name}.tagopt --no-tags`
  `git fetch #{name}`
end
 
desc 'Merge an external project as a sub-tree'
task 'git:subtree:merge' do
  require "readline"
  branch = begin
    print "Branch? "
    Readline.readline.chomp
  end
  dest = begin
    print "Destination? "
    Readline.readline.chomp
  end
  `git merge --squash -s ours --no-commit #{branch}`
  `git read-tree --prefix=#{dest} -u #{branch}`
end
 
desc 'Update an existing subtree project'
task 'git:subtree:update' do
  require "readline"
  branch = begin
    print "Branch? "
    Readline.readline.chomp
  end
  `git merge --squash -s subtree --no-commit #{branch}`
end
 
desc 'Show subtree diff against remote'
task 'git:subtree:diff' do
  require "readline"
  branch = begin
    print "Branch? "
    Readline.readline.chomp
  end
  puts `git-diff-tree -p #{branch}`
end