overapp 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +8 -8
  2. data/Gemfile +1 -1
  3. data/Gemfile.lock +2 -2
  4. data/VERSION +1 -1
  5. data/lib/overapp/files.rb +11 -47
  6. data/lib/overapp/from_command.rb +1 -11
  7. data/lib/overapp/load/base.rb +20 -0
  8. data/lib/overapp/load/factory.rb +19 -0
  9. data/lib/overapp/load/instance.rb +35 -0
  10. data/lib/overapp/load/types/command.rb +19 -0
  11. data/lib/overapp/load/types/empty.rb +9 -0
  12. data/lib/overapp/load/types/local_dir.rb +15 -0
  13. data/lib/overapp/load/types/project.rb +12 -0
  14. data/lib/overapp/load/types/raw_dir.rb +22 -0
  15. data/lib/overapp/load/types/repo.rb +13 -0
  16. data/lib/overapp/project/config.rb +28 -0
  17. data/lib/overapp/project/config_entry.rb +6 -0
  18. data/lib/overapp/project/write.rb +21 -0
  19. data/lib/overapp/project.rb +27 -85
  20. data/lib/overapp/util/cmd.rb +7 -0
  21. data/lib/overapp/util/dir.rb +23 -0
  22. data/lib/overapp/util/git.rb +25 -0
  23. data/lib/overapp/util/tmp_dir.rb +32 -0
  24. data/lib/overapp/util/write.rb +9 -0
  25. data/lib/overapp.rb +23 -27
  26. data/overapp.gemspec +60 -6
  27. data/spec/from_command_spec.rb +19 -7
  28. data/spec/input/rails_post_overlay/.overapp +1 -0
  29. data/spec/input/rails_post_overlay/app/models/post.rb +2 -0
  30. data/spec/input/rails_widget_overlay/.overapp +1 -0
  31. data/spec/input/rails_widget_overlay/app/models/widget.rb +2 -0
  32. data/spec/input/repo/.abc +1 -0
  33. data/spec/input/repo/README.md +1 -0
  34. data/spec/input/repo/b.txt +4 -0
  35. data/spec/input/repo/git_dir/COMMIT_EDITMSG +1 -0
  36. data/spec/input/repo/git_dir/HEAD +1 -0
  37. data/{lib/overapp/thor_file.rb → spec/input/repo/git_dir/MERGE_RR} +0 -0
  38. data/spec/input/repo/git_dir/config +7 -0
  39. data/spec/input/repo/git_dir/description +1 -0
  40. data/spec/input/repo/git_dir/hooks/applypatch-msg.sample +15 -0
  41. data/spec/input/repo/git_dir/hooks/commit-msg.sample +24 -0
  42. data/spec/input/repo/git_dir/hooks/post-update.sample +8 -0
  43. data/spec/input/repo/git_dir/hooks/pre-applypatch.sample +14 -0
  44. data/spec/input/repo/git_dir/hooks/pre-commit.sample +50 -0
  45. data/spec/input/repo/git_dir/hooks/pre-push.sample +53 -0
  46. data/spec/input/repo/git_dir/hooks/pre-rebase.sample +169 -0
  47. data/spec/input/repo/git_dir/hooks/prepare-commit-msg.sample +36 -0
  48. data/spec/input/repo/git_dir/hooks/update.sample +128 -0
  49. data/spec/input/repo/git_dir/index +0 -0
  50. data/spec/input/repo/git_dir/info/exclude +6 -0
  51. data/spec/input/repo/git_dir/logs/HEAD +3 -0
  52. data/spec/input/repo/git_dir/logs/refs/heads/master +3 -0
  53. data/spec/input/repo/git_dir/objects/0f/0920d9d41f24629586ec1c20d2283d7df3a950 +0 -0
  54. data/spec/input/repo/git_dir/objects/16/b5741fe01104ea0bdf50603b4c5d42ae5dcbc1 +2 -0
  55. data/spec/input/repo/git_dir/objects/20/508dfdb202a80e2c533f259a526205448b0152 +0 -0
  56. data/spec/input/repo/git_dir/objects/59/c5d2b4bc66e952a99b3b18a89cbc1e6704ffa0 +0 -0
  57. data/spec/input/repo/git_dir/objects/7b/1c8984cafd98a5b369ef325a85cb80e3985148 +2 -0
  58. data/spec/input/repo/git_dir/objects/bf/9307f21baa545173db65a417026088a033aa91 +2 -0
  59. data/spec/input/repo/git_dir/objects/d6/8dd4031d2ad5b7a3829ad7df6635e27a7daa22 +0 -0
  60. data/spec/input/repo/git_dir/objects/d6/cd9e553ef95332f3b77f70d11d0106ca06071c +0 -0
  61. data/spec/input/repo/git_dir/objects/f8/4c814d15674489c0b41035eb4243ccce522511 +0 -0
  62. data/spec/input/repo/git_dir/refs/heads/master +1 -0
  63. data/spec/input/top/.overlay +1 -1
  64. data/spec/nesting_spec.rb +44 -0
  65. data/spec/project_note_spec.rb +19 -13
  66. data/spec/spec_helper.rb +36 -1
  67. data/spec/support/output_dir.rb +6 -9
  68. data/spec/support/tmp_dir.rb +11 -0
  69. data/tmp/.gitkeep +0 -0
  70. metadata +59 -5
data/lib/overapp.rb CHANGED
@@ -1,38 +1,34 @@
1
1
  require 'mharris_ext'
2
2
 
3
- %w(files template_file thor_file project from_command).each do |f|
4
- load File.dirname(__FILE__) + "/overapp/#{f}.rb"
3
+ class Object
4
+ def klass
5
+ self.class
6
+ end
5
7
  end
6
8
 
7
9
  module Overapp
8
- class << self
9
- def with_repo_path(url)
10
- dir = "/tmp/#{rand(100000000000000000000)}"
11
- `mkdir #{dir}`
12
- Dir.chdir(dir) do
13
- `git clone #{url} .`
14
- end
15
- yield dir
16
- ensure
17
- `rm -rf #{dir}`
10
+ def self.load_files!
11
+ %w(files template_file project from_command).each do |f|
12
+ load File.dirname(__FILE__) + "/overapp/#{f}.rb"
13
+ end
14
+
15
+ %w(base instance factory).each do |f|
16
+ load File.dirname(__FILE__) + "/overapp/load/#{f}.rb"
18
17
  end
19
- def with_local_path(overapp_path,&b)
20
- if overapp_path =~ /git/
21
- with_repo_path(overapp_path) do |dir|
22
- b[dir]
23
- end
24
- else
25
- yield overapp_path
26
- end
18
+
19
+ %w(command raw_dir local_dir repo empty project).each do |f|
20
+ load File.dirname(__FILE__) + "/overapp/load/types/#{f}.rb"
27
21
  end
28
- def write_project(overapp_path,output_path)
29
- with_local_path(overapp_path) do |dir|
30
- Overapp::Project.new(:path => dir).write_to!(output_path)
31
- end
22
+
23
+ %w(config write config_entry).each do |f|
24
+ load File.dirname(__FILE__) + "/overapp/project/#{f}.rb"
32
25
  end
33
26
 
34
- def ec(cmd,ops={})
35
- MharrisExt.ec(cmd,ops)
27
+ %w(tmp_dir git dir cmd write).each do |f|
28
+ load File.dirname(__FILE__) + "/overapp/util/#{f}.rb"
36
29
  end
37
30
  end
38
- end
31
+ end
32
+
33
+ Overapp.load_files!
34
+
data/overapp.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "overapp"
8
- s.version = "0.3.1"
8
+ s.version = "0.4.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Mike Harris"]
12
- s.date = "2013-11-11"
12
+ s.date = "2013-11-15"
13
13
  s.description = "overapp"
14
14
  s.email = "mharris717@gmail.com"
15
15
  s.executables = ["overapp"]
@@ -31,20 +31,74 @@ Gem::Specification.new do |s|
31
31
  "lib/overapp.rb",
32
32
  "lib/overapp/files.rb",
33
33
  "lib/overapp/from_command.rb",
34
+ "lib/overapp/load/base.rb",
35
+ "lib/overapp/load/factory.rb",
36
+ "lib/overapp/load/instance.rb",
37
+ "lib/overapp/load/types/command.rb",
38
+ "lib/overapp/load/types/empty.rb",
39
+ "lib/overapp/load/types/local_dir.rb",
40
+ "lib/overapp/load/types/project.rb",
41
+ "lib/overapp/load/types/raw_dir.rb",
42
+ "lib/overapp/load/types/repo.rb",
34
43
  "lib/overapp/project.rb",
44
+ "lib/overapp/project/config.rb",
45
+ "lib/overapp/project/config_entry.rb",
46
+ "lib/overapp/project/write.rb",
35
47
  "lib/overapp/template_file.rb",
36
- "lib/overapp/thor_file.rb",
48
+ "lib/overapp/util/cmd.rb",
49
+ "lib/overapp/util/dir.rb",
50
+ "lib/overapp/util/git.rb",
51
+ "lib/overapp/util/tmp_dir.rb",
52
+ "lib/overapp/util/write.rb",
37
53
  "overapp.gemspec",
38
54
  "spec/from_command_spec.rb",
55
+ "spec/input/rails_post_overlay/.overapp",
56
+ "spec/input/rails_post_overlay/app/models/post.rb",
57
+ "spec/input/rails_widget_overlay/.overapp",
58
+ "spec/input/rails_widget_overlay/app/models/widget.rb",
59
+ "spec/input/repo/.abc",
60
+ "spec/input/repo/README.md",
61
+ "spec/input/repo/b.txt",
62
+ "spec/input/repo/git_dir/COMMIT_EDITMSG",
63
+ "spec/input/repo/git_dir/HEAD",
64
+ "spec/input/repo/git_dir/MERGE_RR",
65
+ "spec/input/repo/git_dir/config",
66
+ "spec/input/repo/git_dir/description",
67
+ "spec/input/repo/git_dir/hooks/applypatch-msg.sample",
68
+ "spec/input/repo/git_dir/hooks/commit-msg.sample",
69
+ "spec/input/repo/git_dir/hooks/post-update.sample",
70
+ "spec/input/repo/git_dir/hooks/pre-applypatch.sample",
71
+ "spec/input/repo/git_dir/hooks/pre-commit.sample",
72
+ "spec/input/repo/git_dir/hooks/pre-push.sample",
73
+ "spec/input/repo/git_dir/hooks/pre-rebase.sample",
74
+ "spec/input/repo/git_dir/hooks/prepare-commit-msg.sample",
75
+ "spec/input/repo/git_dir/hooks/update.sample",
76
+ "spec/input/repo/git_dir/index",
77
+ "spec/input/repo/git_dir/info/exclude",
78
+ "spec/input/repo/git_dir/logs/HEAD",
79
+ "spec/input/repo/git_dir/logs/refs/heads/master",
80
+ "spec/input/repo/git_dir/objects/0f/0920d9d41f24629586ec1c20d2283d7df3a950",
81
+ "spec/input/repo/git_dir/objects/16/b5741fe01104ea0bdf50603b4c5d42ae5dcbc1",
82
+ "spec/input/repo/git_dir/objects/20/508dfdb202a80e2c533f259a526205448b0152",
83
+ "spec/input/repo/git_dir/objects/59/c5d2b4bc66e952a99b3b18a89cbc1e6704ffa0",
84
+ "spec/input/repo/git_dir/objects/7b/1c8984cafd98a5b369ef325a85cb80e3985148",
85
+ "spec/input/repo/git_dir/objects/bf/9307f21baa545173db65a417026088a033aa91",
86
+ "spec/input/repo/git_dir/objects/d6/8dd4031d2ad5b7a3829ad7df6635e27a7daa22",
87
+ "spec/input/repo/git_dir/objects/d6/cd9e553ef95332f3b77f70d11d0106ca06071c",
88
+ "spec/input/repo/git_dir/objects/f8/4c814d15674489c0b41035eb4243ccce522511",
89
+ "spec/input/repo/git_dir/refs/heads/master",
39
90
  "spec/input/top/.overlay",
40
91
  "spec/input/top/b.txt",
41
92
  "spec/input/top/c.txt",
42
93
  "spec/input/top/place/d.txt",
94
+ "spec/nesting_spec.rb",
43
95
  "spec/overapp_spec.rb",
44
96
  "spec/project_note_spec.rb",
45
97
  "spec/spec_helper.rb",
46
98
  "spec/support/output_dir.rb",
47
99
  "spec/support/setup.rb",
100
+ "spec/support/tmp_dir.rb",
101
+ "tmp/.gitkeep",
48
102
  "vol/input/base/a.txt",
49
103
  "vol/input/base/b.txt",
50
104
  "vol/input/top/.fstemplate",
@@ -63,7 +117,7 @@ Gem::Specification.new do |s|
63
117
  s.specification_version = 4
64
118
 
65
119
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
66
- s.add_runtime_dependency(%q<mharris_ext>, [">= 0"])
120
+ s.add_runtime_dependency(%q<mharris_ext>, [">= 1.7.1"])
67
121
  s.add_runtime_dependency(%q<andand>, [">= 0"])
68
122
  s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
69
123
  s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
@@ -75,7 +129,7 @@ Gem::Specification.new do |s|
75
129
  s.add_development_dependency(%q<rb-fsevent>, ["~> 0.9"])
76
130
  s.add_development_dependency(%q<lre>, [">= 0"])
77
131
  else
78
- s.add_dependency(%q<mharris_ext>, [">= 0"])
132
+ s.add_dependency(%q<mharris_ext>, [">= 1.7.1"])
79
133
  s.add_dependency(%q<andand>, [">= 0"])
80
134
  s.add_dependency(%q<rspec>, ["~> 2.8.0"])
81
135
  s.add_dependency(%q<rdoc>, ["~> 3.12"])
@@ -88,7 +142,7 @@ Gem::Specification.new do |s|
88
142
  s.add_dependency(%q<lre>, [">= 0"])
89
143
  end
90
144
  else
91
- s.add_dependency(%q<mharris_ext>, [">= 0"])
145
+ s.add_dependency(%q<mharris_ext>, [">= 1.7.1"])
92
146
  s.add_dependency(%q<andand>, [">= 0"])
93
147
  s.add_dependency(%q<rspec>, ["~> 2.8.0"])
94
148
  s.add_dependency(%q<rdoc>, ["~> 3.12"])
@@ -1,17 +1,29 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  describe 'FromCommand' do
4
+ include_context "tmp dir"
5
+ include_context "output dir"
6
+
4
7
  let(:command) do
5
8
  "mkdir abc && cd abc && echo stuff > abc.txt"
6
9
  end
7
10
 
8
- let(:from_command) do
9
- Overapp::FromCommand.new(:command => command, :path => "abc")
11
+ let(:config_body) do
12
+ "c.command '#{command}', :path => 'abc'"
13
+ end
14
+
15
+ before do
16
+ File.create "#{tmp_dir}/place.txt","fun"
17
+ end
18
+
19
+ let(:project) do
20
+ res = Overapp::Project.new(:path => tmp_dir)
21
+ res.stub(:config_body) { config_body }
22
+ res
10
23
  end
11
24
 
12
- it 'files' do
13
- from_command.files.size.should == 1
14
- from_command.files.first.path.should == 'abc.txt'
15
- from_command.files.first.full_body.strip.should == 'stuff'
25
+ it 'runs' do
26
+ project.write_to! output_dir
27
+ Dir["#{output_dir}/**/*.*"].should == ['abc.txt','place.txt'].map { |x| "#{output_dir}/#{x}" }
16
28
  end
17
- end
29
+ end
@@ -0,0 +1 @@
1
+ c.base "OVERAPP_ROOT_DIR/spec/input/rails_widget_overlay"
@@ -0,0 +1,2 @@
1
+ class Post < ActiveRecord::Base
2
+ end
@@ -0,0 +1 @@
1
+ c.command "mkdir config && echo route stuff > config/routes.rb"
@@ -0,0 +1,2 @@
1
+ class Widget < ActiveRecord::Base
2
+ end
@@ -0,0 +1 @@
1
+ stuff
@@ -0,0 +1 @@
1
+ Stuff Here
@@ -0,0 +1,4 @@
1
+ a
2
+ b
3
+ c
4
+ d
@@ -0,0 +1 @@
1
+ .abc
@@ -0,0 +1 @@
1
+ ref: refs/heads/master
@@ -0,0 +1,7 @@
1
+ [core]
2
+ repositoryformatversion = 0
3
+ filemode = true
4
+ bare = false
5
+ logallrefupdates = true
6
+ ignorecase = true
7
+ precomposeunicode = false
@@ -0,0 +1 @@
1
+ Unnamed repository; edit this file 'description' to name the repository.
@@ -0,0 +1,15 @@
1
+ #!/bin/sh
2
+ #
3
+ # An example hook script to check the commit log message taken by
4
+ # applypatch from an e-mail message.
5
+ #
6
+ # The hook should exit with non-zero status after issuing an
7
+ # appropriate message if it wants to stop the commit. The hook is
8
+ # allowed to edit the commit message file.
9
+ #
10
+ # To enable this hook, rename this file to "applypatch-msg".
11
+
12
+ . git-sh-setup
13
+ test -x "$GIT_DIR/hooks/commit-msg" &&
14
+ exec "$GIT_DIR/hooks/commit-msg" ${1+"$@"}
15
+ :
@@ -0,0 +1,24 @@
1
+ #!/bin/sh
2
+ #
3
+ # An example hook script to check the commit log message.
4
+ # Called by "git commit" with one argument, the name of the file
5
+ # that has the commit message. The hook should exit with non-zero
6
+ # status after issuing an appropriate message if it wants to stop the
7
+ # commit. The hook is allowed to edit the commit message file.
8
+ #
9
+ # To enable this hook, rename this file to "commit-msg".
10
+
11
+ # Uncomment the below to add a Signed-off-by line to the message.
12
+ # Doing this in a hook is a bad idea in general, but the prepare-commit-msg
13
+ # hook is more suited to it.
14
+ #
15
+ # SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p')
16
+ # grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1"
17
+
18
+ # This example catches duplicate Signed-off-by lines.
19
+
20
+ test "" = "$(grep '^Signed-off-by: ' "$1" |
21
+ sort | uniq -c | sed -e '/^[ ]*1[ ]/d')" || {
22
+ echo >&2 Duplicate Signed-off-by lines.
23
+ exit 1
24
+ }
@@ -0,0 +1,8 @@
1
+ #!/bin/sh
2
+ #
3
+ # An example hook script to prepare a packed repository for use over
4
+ # dumb transports.
5
+ #
6
+ # To enable this hook, rename this file to "post-update".
7
+
8
+ exec git update-server-info
@@ -0,0 +1,14 @@
1
+ #!/bin/sh
2
+ #
3
+ # An example hook script to verify what is about to be committed
4
+ # by applypatch from an e-mail message.
5
+ #
6
+ # The hook should exit with non-zero status after issuing an
7
+ # appropriate message if it wants to stop the commit.
8
+ #
9
+ # To enable this hook, rename this file to "pre-applypatch".
10
+
11
+ . git-sh-setup
12
+ test -x "$GIT_DIR/hooks/pre-commit" &&
13
+ exec "$GIT_DIR/hooks/pre-commit" ${1+"$@"}
14
+ :
@@ -0,0 +1,50 @@
1
+ #!/bin/sh
2
+ #
3
+ # An example hook script to verify what is about to be committed.
4
+ # Called by "git commit" with no arguments. The hook should
5
+ # exit with non-zero status after issuing an appropriate message if
6
+ # it wants to stop the commit.
7
+ #
8
+ # To enable this hook, rename this file to "pre-commit".
9
+
10
+ if git rev-parse --verify HEAD >/dev/null 2>&1
11
+ then
12
+ against=HEAD
13
+ else
14
+ # Initial commit: diff against an empty tree object
15
+ against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
16
+ fi
17
+
18
+ # If you want to allow non-ascii filenames set this variable to true.
19
+ allownonascii=$(git config hooks.allownonascii)
20
+
21
+ # Redirect output to stderr.
22
+ exec 1>&2
23
+
24
+ # Cross platform projects tend to avoid non-ascii filenames; prevent
25
+ # them from being added to the repository. We exploit the fact that the
26
+ # printable range starts at the space character and ends with tilde.
27
+ if [ "$allownonascii" != "true" ] &&
28
+ # Note that the use of brackets around a tr range is ok here, (it's
29
+ # even required, for portability to Solaris 10's /usr/bin/tr), since
30
+ # the square bracket bytes happen to fall in the designated range.
31
+ test $(git diff --cached --name-only --diff-filter=A -z $against |
32
+ LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0
33
+ then
34
+ echo "Error: Attempt to add a non-ascii file name."
35
+ echo
36
+ echo "This can cause problems if you want to work"
37
+ echo "with people on other platforms."
38
+ echo
39
+ echo "To be portable it is advisable to rename the file ..."
40
+ echo
41
+ echo "If you know what you are doing you can disable this"
42
+ echo "check using:"
43
+ echo
44
+ echo " git config hooks.allownonascii true"
45
+ echo
46
+ exit 1
47
+ fi
48
+
49
+ # If there are whitespace errors, print the offending file names and fail.
50
+ exec git diff-index --check --cached $against --
@@ -0,0 +1,53 @@
1
+ #!/bin/sh
2
+
3
+ # An example hook script to verify what is about to be pushed. Called by "git
4
+ # push" after it has checked the remote status, but before anything has been
5
+ # pushed. If this script exits with a non-zero status nothing will be pushed.
6
+ #
7
+ # This hook is called with the following parameters:
8
+ #
9
+ # $1 -- Name of the remote to which the push is being done
10
+ # $2 -- URL to which the push is being done
11
+ #
12
+ # If pushing without using a named remote those arguments will be equal.
13
+ #
14
+ # Information about the commits which are being pushed is supplied as lines to
15
+ # the standard input in the form:
16
+ #
17
+ # <local ref> <local sha1> <remote ref> <remote sha1>
18
+ #
19
+ # This sample shows how to prevent push of commits where the log message starts
20
+ # with "WIP" (work in progress).
21
+
22
+ remote="$1"
23
+ url="$2"
24
+
25
+ z40=0000000000000000000000000000000000000000
26
+
27
+ IFS=' '
28
+ while read local_ref local_sha remote_ref remote_sha
29
+ do
30
+ if [ "$local_sha" = $z40 ]
31
+ then
32
+ # Handle delete
33
+ else
34
+ if [ "$remote_sha" = $z40 ]
35
+ then
36
+ # New branch, examine all commits
37
+ range="$local_sha"
38
+ else
39
+ # Update to existing branch, examine new commits
40
+ range="$remote_sha..$local_sha"
41
+ fi
42
+
43
+ # Check for WIP commit
44
+ commit=`git rev-list -n 1 --grep '^WIP' "$range"`
45
+ if [ -n "$commit" ]
46
+ then
47
+ echo "Found WIP commit in $local_ref, not pushing"
48
+ exit 1
49
+ fi
50
+ fi
51
+ done
52
+
53
+ exit 0
@@ -0,0 +1,169 @@
1
+ #!/bin/sh
2
+ #
3
+ # Copyright (c) 2006, 2008 Junio C Hamano
4
+ #
5
+ # The "pre-rebase" hook is run just before "git rebase" starts doing
6
+ # its job, and can prevent the command from running by exiting with
7
+ # non-zero status.
8
+ #
9
+ # The hook is called with the following parameters:
10
+ #
11
+ # $1 -- the upstream the series was forked from.
12
+ # $2 -- the branch being rebased (or empty when rebasing the current branch).
13
+ #
14
+ # This sample shows how to prevent topic branches that are already
15
+ # merged to 'next' branch from getting rebased, because allowing it
16
+ # would result in rebasing already published history.
17
+
18
+ publish=next
19
+ basebranch="$1"
20
+ if test "$#" = 2
21
+ then
22
+ topic="refs/heads/$2"
23
+ else
24
+ topic=`git symbolic-ref HEAD` ||
25
+ exit 0 ;# we do not interrupt rebasing detached HEAD
26
+ fi
27
+
28
+ case "$topic" in
29
+ refs/heads/??/*)
30
+ ;;
31
+ *)
32
+ exit 0 ;# we do not interrupt others.
33
+ ;;
34
+ esac
35
+
36
+ # Now we are dealing with a topic branch being rebased
37
+ # on top of master. Is it OK to rebase it?
38
+
39
+ # Does the topic really exist?
40
+ git show-ref -q "$topic" || {
41
+ echo >&2 "No such branch $topic"
42
+ exit 1
43
+ }
44
+
45
+ # Is topic fully merged to master?
46
+ not_in_master=`git rev-list --pretty=oneline ^master "$topic"`
47
+ if test -z "$not_in_master"
48
+ then
49
+ echo >&2 "$topic is fully merged to master; better remove it."
50
+ exit 1 ;# we could allow it, but there is no point.
51
+ fi
52
+
53
+ # Is topic ever merged to next? If so you should not be rebasing it.
54
+ only_next_1=`git rev-list ^master "^$topic" ${publish} | sort`
55
+ only_next_2=`git rev-list ^master ${publish} | sort`
56
+ if test "$only_next_1" = "$only_next_2"
57
+ then
58
+ not_in_topic=`git rev-list "^$topic" master`
59
+ if test -z "$not_in_topic"
60
+ then
61
+ echo >&2 "$topic is already up-to-date with master"
62
+ exit 1 ;# we could allow it, but there is no point.
63
+ else
64
+ exit 0
65
+ fi
66
+ else
67
+ not_in_next=`git rev-list --pretty=oneline ^${publish} "$topic"`
68
+ /usr/bin/perl -e '
69
+ my $topic = $ARGV[0];
70
+ my $msg = "* $topic has commits already merged to public branch:\n";
71
+ my (%not_in_next) = map {
72
+ /^([0-9a-f]+) /;
73
+ ($1 => 1);
74
+ } split(/\n/, $ARGV[1]);
75
+ for my $elem (map {
76
+ /^([0-9a-f]+) (.*)$/;
77
+ [$1 => $2];
78
+ } split(/\n/, $ARGV[2])) {
79
+ if (!exists $not_in_next{$elem->[0]}) {
80
+ if ($msg) {
81
+ print STDERR $msg;
82
+ undef $msg;
83
+ }
84
+ print STDERR " $elem->[1]\n";
85
+ }
86
+ }
87
+ ' "$topic" "$not_in_next" "$not_in_master"
88
+ exit 1
89
+ fi
90
+
91
+ exit 0
92
+
93
+ ################################################################
94
+
95
+ This sample hook safeguards topic branches that have been
96
+ published from being rewound.
97
+
98
+ The workflow assumed here is:
99
+
100
+ * Once a topic branch forks from "master", "master" is never
101
+ merged into it again (either directly or indirectly).
102
+
103
+ * Once a topic branch is fully cooked and merged into "master",
104
+ it is deleted. If you need to build on top of it to correct
105
+ earlier mistakes, a new topic branch is created by forking at
106
+ the tip of the "master". This is not strictly necessary, but
107
+ it makes it easier to keep your history simple.
108
+
109
+ * Whenever you need to test or publish your changes to topic
110
+ branches, merge them into "next" branch.
111
+
112
+ The script, being an example, hardcodes the publish branch name
113
+ to be "next", but it is trivial to make it configurable via
114
+ $GIT_DIR/config mechanism.
115
+
116
+ With this workflow, you would want to know:
117
+
118
+ (1) ... if a topic branch has ever been merged to "next". Young
119
+ topic branches can have stupid mistakes you would rather
120
+ clean up before publishing, and things that have not been
121
+ merged into other branches can be easily rebased without
122
+ affecting other people. But once it is published, you would
123
+ not want to rewind it.
124
+
125
+ (2) ... if a topic branch has been fully merged to "master".
126
+ Then you can delete it. More importantly, you should not
127
+ build on top of it -- other people may already want to
128
+ change things related to the topic as patches against your
129
+ "master", so if you need further changes, it is better to
130
+ fork the topic (perhaps with the same name) afresh from the
131
+ tip of "master".
132
+
133
+ Let's look at this example:
134
+
135
+ o---o---o---o---o---o---o---o---o---o "next"
136
+ / / / /
137
+ / a---a---b A / /
138
+ / / / /
139
+ / / c---c---c---c B /
140
+ / / / \ /
141
+ / / / b---b C \ /
142
+ / / / / \ /
143
+ ---o---o---o---o---o---o---o---o---o---o---o "master"
144
+
145
+
146
+ A, B and C are topic branches.
147
+
148
+ * A has one fix since it was merged up to "next".
149
+
150
+ * B has finished. It has been fully merged up to "master" and "next",
151
+ and is ready to be deleted.
152
+
153
+ * C has not merged to "next" at all.
154
+
155
+ We would want to allow C to be rebased, refuse A, and encourage
156
+ B to be deleted.
157
+
158
+ To compute (1):
159
+
160
+ git rev-list ^master ^topic next
161
+ git rev-list ^master next
162
+
163
+ if these match, topic has not merged in next at all.
164
+
165
+ To compute (2):
166
+
167
+ git rev-list master..topic
168
+
169
+ if this is empty, it is fully merged to "master".
@@ -0,0 +1,36 @@
1
+ #!/bin/sh
2
+ #
3
+ # An example hook script to prepare the commit log message.
4
+ # Called by "git commit" with the name of the file that has the
5
+ # commit message, followed by the description of the commit
6
+ # message's source. The hook's purpose is to edit the commit
7
+ # message file. If the hook fails with a non-zero status,
8
+ # the commit is aborted.
9
+ #
10
+ # To enable this hook, rename this file to "prepare-commit-msg".
11
+
12
+ # This hook includes three examples. The first comments out the
13
+ # "Conflicts:" part of a merge commit.
14
+ #
15
+ # The second includes the output of "git diff --name-status -r"
16
+ # into the message, just before the "git status" output. It is
17
+ # commented because it doesn't cope with --amend or with squashed
18
+ # commits.
19
+ #
20
+ # The third example adds a Signed-off-by line to the message, that can
21
+ # still be edited. This is rarely a good idea.
22
+
23
+ case "$2,$3" in
24
+ merge,)
25
+ /usr/bin/perl -i.bak -ne 's/^/# /, s/^# #/#/ if /^Conflicts/ .. /#/; print' "$1" ;;
26
+
27
+ # ,|template,)
28
+ # /usr/bin/perl -i.bak -pe '
29
+ # print "\n" . `git diff --cached --name-status -r`
30
+ # if /^#/ && $first++ == 0' "$1" ;;
31
+
32
+ *) ;;
33
+ esac
34
+
35
+ # SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p')
36
+ # grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1"