git-object-browser 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (146) hide show
  1. data/.gitignore +17 -0
  2. data/.rspec +2 -0
  3. data/Gemfile +13 -0
  4. data/Guardfile +11 -0
  5. data/LICENSE +22 -0
  6. data/README.md +18 -0
  7. data/Rakefile +2 -0
  8. data/bin/git-object-browser +5 -0
  9. data/git-object-browser.gemspec +18 -0
  10. data/htdocs/css/angular-ui.min.css +1 -0
  11. data/htdocs/css/bootstrap-responsive.css +1058 -0
  12. data/htdocs/css/bootstrap-responsive.min.css +9 -0
  13. data/htdocs/css/bootstrap.css +5389 -0
  14. data/htdocs/css/bootstrap.min.css +699 -0
  15. data/htdocs/css/font-awesome-ie7.css +645 -0
  16. data/htdocs/css/font-awesome.css +303 -0
  17. data/htdocs/css/main.css +22 -0
  18. data/htdocs/font/fontawesome-webfont.eot +0 -0
  19. data/htdocs/font/fontawesome-webfont.svg +255 -0
  20. data/htdocs/font/fontawesome-webfont.ttf +0 -0
  21. data/htdocs/font/fontawesome-webfont.woff +0 -0
  22. data/htdocs/img/glyphicons-halflings-white.png +0 -0
  23. data/htdocs/img/glyphicons-halflings.png +0 -0
  24. data/htdocs/index.html +114 -0
  25. data/htdocs/js/main.js +286 -0
  26. data/htdocs/js/vendor/angular-bootstrap-prettify.min.js +41 -0
  27. data/htdocs/js/vendor/angular-bootstrap.min.js +9 -0
  28. data/htdocs/js/vendor/angular-cookies.min.js +7 -0
  29. data/htdocs/js/vendor/angular-loader.min.js +7 -0
  30. data/htdocs/js/vendor/angular-resource.min.js +10 -0
  31. data/htdocs/js/vendor/angular-sanitize.min.js +13 -0
  32. data/htdocs/js/vendor/angular-ui-ieshiv.min.js +7 -0
  33. data/htdocs/js/vendor/angular-ui.min.js +7 -0
  34. data/htdocs/js/vendor/angular.js +14401 -0
  35. data/htdocs/js/vendor/angular.min.js +158 -0
  36. data/htdocs/js/vendor/bootstrap.js +2027 -0
  37. data/htdocs/js/vendor/bootstrap.min.js +6 -0
  38. data/htdocs/js/vendor/html5shiv.js +5 -0
  39. data/htdocs/js/vendor/jquery-1.8.2.min.js +2 -0
  40. data/htdocs/templates/directory.html +25 -0
  41. data/htdocs/templates/file.html +6 -0
  42. data/htdocs/templates/git.html +1 -0
  43. data/htdocs/templates/index.html +44 -0
  44. data/htdocs/templates/index_entry.html +54 -0
  45. data/htdocs/templates/info_refs.html +27 -0
  46. data/htdocs/templates/loading.html +1 -0
  47. data/htdocs/templates/notfound.html +7 -0
  48. data/htdocs/templates/object.html +54 -0
  49. data/htdocs/templates/objects.html +16 -0
  50. data/htdocs/templates/pack_file.html +15 -0
  51. data/htdocs/templates/pack_index.html +38 -0
  52. data/htdocs/templates/packed_object.html +111 -0
  53. data/htdocs/templates/packed_refs.html +27 -0
  54. data/htdocs/templates/ref.html +12 -0
  55. data/lib/git-object-browser.rb +37 -0
  56. data/lib/git-object-browser/dumper.rb +62 -0
  57. data/lib/git-object-browser/index_dumper.rb +77 -0
  58. data/lib/git-object-browser/main.rb +63 -0
  59. data/lib/git-object-browser/models/bindata.rb +68 -0
  60. data/lib/git-object-browser/models/directory.rb +61 -0
  61. data/lib/git-object-browser/models/git_object.rb +127 -0
  62. data/lib/git-object-browser/models/index.rb +77 -0
  63. data/lib/git-object-browser/models/index_entry.rb +95 -0
  64. data/lib/git-object-browser/models/index_reuc_extension.rb +31 -0
  65. data/lib/git-object-browser/models/index_tree_extension.rb +52 -0
  66. data/lib/git-object-browser/models/info_refs.rb +32 -0
  67. data/lib/git-object-browser/models/pack_file.rb +40 -0
  68. data/lib/git-object-browser/models/pack_index.rb +146 -0
  69. data/lib/git-object-browser/models/packed_object.rb +239 -0
  70. data/lib/git-object-browser/models/packed_refs.rb +39 -0
  71. data/lib/git-object-browser/models/plain_file.rb +24 -0
  72. data/lib/git-object-browser/models/ref.rb +32 -0
  73. data/lib/git-object-browser/object_dumper.rb +31 -0
  74. data/lib/git-object-browser/server/git_servlet.rb +209 -0
  75. data/lib/git-object-browser/server/main.rb +31 -0
  76. data/lib/git-object-browser/version.rb +3 -0
  77. data/spec/fixtures/generate_worktree.sh +103 -0
  78. data/spec/fixtures/git/indexes/001 +0 -0
  79. data/spec/fixtures/git/indexes/002-empty-tree-extension +0 -0
  80. data/spec/fixtures/git/plain_file +1 -0
  81. data/spec/fixtures/json/blob.json +9 -0
  82. data/spec/fixtures/json/merge-a.json +48 -0
  83. data/spec/fixtures/json/test3-tag.json +36 -0
  84. data/spec/fixtures/json/tree.json +20 -0
  85. data/spec/fixtures/worktree/_git/COMMIT_EDITMSG +1 -0
  86. data/spec/fixtures/worktree/_git/HEAD +1 -0
  87. data/spec/fixtures/worktree/_git/ORIG_HEAD +1 -0
  88. data/spec/fixtures/worktree/_git/config +11 -0
  89. data/spec/fixtures/worktree/_git/description +1 -0
  90. data/spec/fixtures/worktree/_git/hooks/applypatch-msg.sample +15 -0
  91. data/spec/fixtures/worktree/_git/hooks/commit-msg.sample +24 -0
  92. data/spec/fixtures/worktree/_git/hooks/post-update.sample +8 -0
  93. data/spec/fixtures/worktree/_git/hooks/pre-applypatch.sample +14 -0
  94. data/spec/fixtures/worktree/_git/hooks/pre-commit.sample +50 -0
  95. data/spec/fixtures/worktree/_git/hooks/pre-rebase.sample +169 -0
  96. data/spec/fixtures/worktree/_git/hooks/prepare-commit-msg.sample +36 -0
  97. data/spec/fixtures/worktree/_git/hooks/update.sample +128 -0
  98. data/spec/fixtures/worktree/_git/ignore +3 -0
  99. data/spec/fixtures/worktree/_git/index +0 -0
  100. data/spec/fixtures/worktree/_git/info/exclude +6 -0
  101. data/spec/fixtures/worktree/_git/info/refs +1 -0
  102. data/spec/fixtures/worktree/_git/logs/HEAD +10 -0
  103. data/spec/fixtures/worktree/_git/logs/refs/heads/branch-a +3 -0
  104. data/spec/fixtures/worktree/_git/logs/refs/heads/branch-b +2 -0
  105. data/spec/fixtures/worktree/_git/logs/refs/heads/master +4 -0
  106. data/spec/fixtures/worktree/_git/objects/00/cb8bfeb5b8ce906d39698e4e33b38341f5448f +1 -0
  107. data/spec/fixtures/worktree/_git/objects/07/31f9d4b6fa0475872be6a8ca263096f1d201cf +2 -0
  108. data/spec/fixtures/worktree/_git/objects/1d/3dc60b5a117054e43741d51e599ff31bb15f9f +0 -0
  109. data/spec/fixtures/worktree/_git/objects/26/4e42b1fef5bcb55acec162fdd5a068d79ae551 +0 -0
  110. data/spec/fixtures/worktree/_git/objects/28/3c06ddf1b31c14bb221d41173299e133b7753d +0 -0
  111. data/spec/fixtures/worktree/_git/objects/37/d1632d3f1159dad9cfb58e6c34312ab4355c49 +0 -0
  112. data/spec/fixtures/worktree/_git/objects/3a/2bf444f105c19b13ba5e75e884e10715e95a91 +0 -0
  113. data/spec/fixtures/worktree/_git/objects/40/a061aaf0cd0555449671a11993e4fed11f91a4 +2 -0
  114. data/spec/fixtures/worktree/_git/objects/53/2a1874c26cd19bd4d66e03218ab73e63de4357 +3 -0
  115. data/spec/fixtures/worktree/_git/objects/5b/719b165fde1964fb5a08adaf3b6e4f57ca1ff5 +0 -0
  116. data/spec/fixtures/worktree/_git/objects/61/cae34206bb889bae43ffdd22c17217485178bf +0 -0
  117. data/spec/fixtures/worktree/_git/objects/6c/444ac15f1e3c2a6869bd36ca7e58c39512106f +2 -0
  118. data/spec/fixtures/worktree/_git/objects/93/b714995d24c52180195876058a49c7d7fea0ad +0 -0
  119. data/spec/fixtures/worktree/_git/objects/96/25401ac3e19ef10868c140a76b719ac3f08fcf +0 -0
  120. data/spec/fixtures/worktree/_git/objects/b9/29ed2ab14f7489d5238a06d10d2f2c229a4ab4 +0 -0
  121. data/spec/fixtures/worktree/_git/objects/be/e0d26d33c284ee065e38bd7e81ae4bdc870f89 +4 -0
  122. data/spec/fixtures/worktree/_git/objects/c3/6491256978d26c08cd7aa97eee0f5631f96659 +0 -0
  123. data/spec/fixtures/worktree/_git/objects/d2/34c5e057fe32c676ea67e8cb38f4625ddaeb54 +0 -0
  124. data/spec/fixtures/worktree/_git/objects/df/6b0d2bcc76e6ec0fca20c227104a4f28bac41b +0 -0
  125. data/spec/fixtures/worktree/_git/objects/e5/b6d4317cefa946d77fc91539f1f1e48b60836f +0 -0
  126. data/spec/fixtures/worktree/_git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 +0 -0
  127. data/spec/fixtures/worktree/_git/objects/info/packs +2 -0
  128. data/spec/fixtures/worktree/_git/objects/pack/pack-f1c1717e9264c12310c7bd3e7dcdd28924000ff6.idx +0 -0
  129. data/spec/fixtures/worktree/_git/objects/pack/pack-f1c1717e9264c12310c7bd3e7dcdd28924000ff6.pack +0 -0
  130. data/spec/fixtures/worktree/_git/packed-refs +2 -0
  131. data/spec/fixtures/worktree/_git/refs/heads/branch-a +1 -0
  132. data/spec/fixtures/worktree/_git/refs/heads/branch-b +1 -0
  133. data/spec/fixtures/worktree/_git/refs/heads/master +1 -0
  134. data/spec/fixtures/worktree/_git/refs/tags/simple-tag +1 -0
  135. data/spec/fixtures/worktree/_git/refs/tags/test3-tag +1 -0
  136. data/spec/fixtures/worktree/sample-a.txt +1 -0
  137. data/spec/fixtures/worktree/sample.txt +1 -0
  138. data/spec/fixtures/worktree/subdir/sample-sub.txt +0 -0
  139. data/spec/git-object-browser/main_spec.rb +31 -0
  140. data/spec/git-object-browser/models/bindata_spec.rb +144 -0
  141. data/spec/git-object-browser/models/git_object_spec.rb +49 -0
  142. data/spec/git-object-browser/models/index_spec.rb +42 -0
  143. data/spec/git-object-browser/models/index_tree_extension_spec.rb +58 -0
  144. data/spec/git-object-browser/models/plain_file_spec.rb +11 -0
  145. data/spec/spec_helper.rb +19 -0
  146. metadata +260 -0
@@ -0,0 +1,31 @@
1
+ require 'webrick'
2
+
3
+ module GitObjectBrowser
4
+
5
+ module Server
6
+
7
+ class Main
8
+
9
+ def initialize(target)
10
+ @target = target
11
+ end
12
+
13
+ def start(host, port)
14
+ root = File.dirname(File.dirname(File.dirname(File.dirname(__FILE__))))
15
+ root = File.expand_path(File.join(root, "htdocs"))
16
+ opts = { :BindAddress => host, :Port => port, :DocumentRoot => root }
17
+ server = WEBrick::HTTPServer.new(opts)
18
+ server.mount('/.git', GitServlet, @target)
19
+ trap 'INT' do
20
+ server.shutdown
21
+ end
22
+ server.start
23
+ end
24
+
25
+ def self.execute(target, host, port)
26
+ self.new(target).start(host, port)
27
+ end
28
+
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,3 @@
1
+ module GitObjectBrowser
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,103 @@
1
+ #! /bin/sh
2
+
3
+ ROOT=`dirname $0`
4
+
5
+ DIR=$ROOT/worktree
6
+ rm -rf $DIR
7
+
8
+ mkdir $DIR
9
+ cd $DIR
10
+
11
+ export GIT_WORK_TREE=.
12
+ export GIT_DIR=_git
13
+
14
+ git init
15
+
16
+ cat > _git/config <<EOF
17
+ [user]
18
+ name = git sample
19
+ email = git@example.com
20
+
21
+ [core]
22
+ repositoryformatversion = 0
23
+ filemode = true
24
+ bare = false
25
+ logallrefupdates = true
26
+ ignorecase = true
27
+ excludesfile = _git/ignore
28
+ EOF
29
+
30
+ cat > _git/ignore <<EOF
31
+ *~
32
+ .DS_Store
33
+ _git
34
+ EOF
35
+
36
+ setdate() {
37
+ export GIT_AUTHOR_DATE=2001-02-03T04:${1}Z
38
+ export GIT_COMMITTER_DATE=$GIT_AUTHOR_DATE
39
+ }
40
+
41
+ echo test > sample.txt
42
+ git add sample.txt
43
+ setdate "00:00"
44
+ git commit -m 'commit 0'
45
+
46
+ echo test1 > sample.txt
47
+ git add sample.txt
48
+ setdate "00:01"
49
+ git commit -m 'commit 1'
50
+
51
+ echo test2 > sample.txt
52
+ git add sample.txt
53
+ setdate "00:02"
54
+ git commit -m 'commit 2'
55
+
56
+ git gc
57
+
58
+ echo test3 > sample.txt
59
+ git add sample.txt
60
+ setdate "00:03"
61
+ git commit -m 'commit 3'
62
+
63
+ git tag -a test3-tag -m 'tag for commit 3'
64
+
65
+ echo test4 > sample.txt
66
+ git add sample.txt
67
+ setdate "00:04"
68
+ git commit -m 'commit 4'
69
+
70
+ git tag simple-tag
71
+
72
+ git branch branch-a
73
+ git branch branch-b
74
+
75
+ git checkout branch-a
76
+
77
+ echo test4a-1 > sample-a.txt
78
+ git add sample-a.txt
79
+ setdate "00:05"
80
+ git commit -m 'commit 4a-1'
81
+
82
+ echo test4a-2 > sample-a.txt
83
+ git add sample-a.txt
84
+ setdate "00:06"
85
+ git commit -m 'commit 4a-2'
86
+
87
+ git checkout branch-b
88
+
89
+ echo test4b-1 > sample-b.txt
90
+ git add sample-b.txt
91
+ setdate "00:07"
92
+ git commit -m 'commit 4b-1'
93
+
94
+ git checkout master
95
+
96
+ setdate "00:08"
97
+ git merge --no-ff branch-a -m 'merge a'
98
+
99
+ setdate "00:09"
100
+ mkdir subdir
101
+ touch subdir/sample-sub.txt
102
+ git add subdir/sample-sub.txt
103
+ git commit -m 'add subdir'
@@ -0,0 +1 @@
1
+ sample
@@ -0,0 +1,9 @@
1
+ {
2
+ "type": "blob",
3
+ "sha1": "d234c5e057fe32c676ea67e8cb38f4625ddaeb54",
4
+ "size": "6",
5
+ "entries": null,
6
+ "content": "test4\n",
7
+ "properties": null,
8
+ "message": null
9
+ }
@@ -0,0 +1,48 @@
1
+ {
2
+ "type": "commit",
3
+ "sha1": "37d1632d3f1159dad9cfb58e6c34312ab4355c49",
4
+ "size": "258",
5
+ "entries": null,
6
+ "content": "tree c36491256978d26c08cd7aa97eee0f5631f96659\nparent 93b714995d24c52180195876058a49c7d7fea0ad\nparent bee0d26d33c284ee065e38bd7e81ae4bdc870f89\nauthor git sample <git@example.com> 981172808 +0000\ncommitter git sample <git@example.com> 981172808 +0000\n\nmerge a\n",
7
+ "properties": [
8
+ {
9
+ "key": "tree",
10
+ "value": "c36491256978d26c08cd7aa97eee0f5631f96659",
11
+ "type": "sha1",
12
+ "path": "objects/c3/6491256978d26c08cd7aa97eee0f5631f96659"
13
+ },
14
+ {
15
+ "key": "parent",
16
+ "value": "93b714995d24c52180195876058a49c7d7fea0ad",
17
+ "type": "sha1",
18
+ "path": "objects/93/b714995d24c52180195876058a49c7d7fea0ad"
19
+ },
20
+ {
21
+ "key": "parent",
22
+ "value": "bee0d26d33c284ee065e38bd7e81ae4bdc870f89",
23
+ "type": "sha1",
24
+ "path": "objects/be/e0d26d33c284ee065e38bd7e81ae4bdc870f89"
25
+ },
26
+ {
27
+ "key": "author",
28
+ "value": "git sample <git@example.com> 981172808 +0000",
29
+ "type": "user",
30
+ "name": "git sample",
31
+ "email": "git@example.com",
32
+ "unixtime": "981172808",
33
+ "timezone": "+0000",
34
+ "date": "2001-02-03T04:00:08+00:00"
35
+ },
36
+ {
37
+ "key": "committer",
38
+ "value": "git sample <git@example.com> 981172808 +0000",
39
+ "type": "user",
40
+ "name": "git sample",
41
+ "email": "git@example.com",
42
+ "unixtime": "981172808",
43
+ "timezone": "+0000",
44
+ "date": "2001-02-03T04:00:08+00:00"
45
+ }
46
+ ],
47
+ "message": "merge a"
48
+ }
@@ -0,0 +1,36 @@
1
+ {
2
+ "type": "tag",
3
+ "sha1": "00cb8bfeb5b8ce906d39698e4e33b38341f5448f",
4
+ "size": "144",
5
+ "entries": null,
6
+ "content": "object 532a1874c26cd19bd4d66e03218ab73e63de4357\ntype commit\ntag test3-tag\ntagger git sample <git@example.com> 981172803 +0000\n\ntag for commit 3\n",
7
+ "properties": [
8
+ {
9
+ "key": "object",
10
+ "value": "532a1874c26cd19bd4d66e03218ab73e63de4357",
11
+ "type": "sha1",
12
+ "path": "objects/53/2a1874c26cd19bd4d66e03218ab73e63de4357"
13
+ },
14
+ {
15
+ "key": "type",
16
+ "value": "commit",
17
+ "type": "text"
18
+ },
19
+ {
20
+ "key": "tag",
21
+ "value": "test3-tag",
22
+ "type": "text"
23
+ },
24
+ {
25
+ "key": "tagger",
26
+ "value": "git sample <git@example.com> 981172803 +0000",
27
+ "type": "user",
28
+ "name": "git sample",
29
+ "email": "git@example.com",
30
+ "unixtime": "981172803",
31
+ "timezone": "+0000",
32
+ "date": "2001-02-03T04:00:03+00:00"
33
+ }
34
+ ],
35
+ "message": "tag for commit 3"
36
+ }
@@ -0,0 +1,20 @@
1
+ {
2
+ "type": "tree",
3
+ "sha1": "c36491256978d26c08cd7aa97eee0f5631f96659",
4
+ "size": "78",
5
+ "entries": [
6
+ {
7
+ "mode": "100644",
8
+ "filename": "sample-a.txt",
9
+ "sha1": "1d3dc60b5a117054e43741d51e599ff31bb15f9f"
10
+ },
11
+ {
12
+ "mode": "100644",
13
+ "filename": "sample.txt",
14
+ "sha1": "d234c5e057fe32c676ea67e8cb38f4625ddaeb54"
15
+ }
16
+ ],
17
+ "content": null,
18
+ "properties": null,
19
+ "message": null
20
+ }
@@ -0,0 +1 @@
1
+ add subdir
@@ -0,0 +1 @@
1
+ ref: refs/heads/master
@@ -0,0 +1 @@
1
+ 93b714995d24c52180195876058a49c7d7fea0ad
@@ -0,0 +1,11 @@
1
+ [user]
2
+ name = git sample
3
+ email = git@example.com
4
+
5
+ [core]
6
+ repositoryformatversion = 0
7
+ filemode = true
8
+ bare = false
9
+ logallrefupdates = true
10
+ ignorecase = true
11
+ excludesfile = _git/ignore
@@ -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,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".