fossgit 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +35 -0
  3. data/README.md +57 -0
  4. data/bin/fossgit +158 -0
  5. data/lib/fossgit.rb +5 -0
  6. metadata +59 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ff8a4c882972941862c63ab14c1a6a7612523c3e
4
+ data.tar.gz: f7057fc31c57762a4d3ff715a66a8c0a9ef23eb8
5
+ SHA512:
6
+ metadata.gz: 46fc13e318b8ae5bcf8303e2f6ea6e6868894c3537d5eeed767a8f98fda325af781a3ff8dfc4de111da9001f9542830772db02258abaec5e63e968d99da4bc77
7
+ data.tar.gz: 065d66e51b3073b7cec46bc8bbf238a555a5af678634f1b45d568ad558e47d84502a5faa73a3a6e8a59fbea3bd34b51fbd6a4bd627cfea4fc2baeb8c0354be09
data/LICENSE ADDED
@@ -0,0 +1,35 @@
1
+ FossGit: Copyright 2016 Chad Perrin, released under the terms of version 0.4 of
2
+ the Copyfree Open Innovation License.
3
+
4
+ ## Terms and Conditions
5
+
6
+ Redistributions, modified or unmodified, in whole or in part, must retain
7
+ applicable copyright or other legal privilege notices, these conditions, and
8
+ the following license terms and disclaimer. Subject to these conditions, the
9
+ holder(s) of copyright or other legal privileges, author(s) or assembler(s),
10
+ and contributors of this work hereby grant to any person who obtains a copy of
11
+ this work in any form:
12
+
13
+ 1. Permission to reproduce, modify, distribute, publish, sell, sublicense, use,
14
+ and/or otherwise deal in the licensed material without restriction.
15
+
16
+ 2. A perpetual, worldwide, non-exclusive, royalty-free, irrevocable patent
17
+ license to reproduce, modify, distribute, publish, sell, use, and/or otherwise
18
+ deal in the licensed material without restriction, for any and all patents:
19
+
20
+ a. Held presently or in the future by each such holder of copyright or
21
+ other legal privilege, author or assembler, or contributor, necessarily
22
+ infringed by the contributions alone or by combination with the work, of
23
+ that privilege holder, author or assembler, or contributor.
24
+
25
+ b. Necessarily infringed by the work at the time that holder of copyright
26
+ or other privilege, author or assembler, or contributor made any
27
+ contribution to the work.
28
+
29
+ NO WARRANTY OF ANY KIND IS IMPLIED BY, OR SHOULD BE INFERRED FROM, THIS LICENSE
30
+ OR THE ACT OF DISTRIBUTION UNDER THE TERMS OF THIS LICENSE, INCLUDING BUT NOT
31
+ LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
32
+ AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS, ASSEMBLERS, OR HOLDERS OF
33
+ COPYRIGHT OR OTHER LEGAL PRIVILEGE BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER
34
+ LIABILITY, WHETHER IN ACTION OF CONTRACT, TORT, OR OTHERWISE ARISING FROM, OUT
35
+ OF, OR IN CONNECTION WITH THE WORK OR THE USE OF OR OTHER DEALINGS IN THE WORK.
data/README.md ADDED
@@ -0,0 +1,57 @@
1
+ # fossgit
2
+
3
+ This is a simple command line utility for creating and updating Git
4
+ repositories as (one-way) mirrors of Fossil repositories.
5
+
6
+ ## Installation
7
+
8
+ Clone it from the [Fossil repository](https://fossrec.com/u/apotheon/fossgit/)
9
+ or the [GitHub mirror](https://github.com/apotheon/fossgit/).
10
+
11
+ Copy the `fossgit` file to a directory in your execution path, create a symlink
12
+ or hardlink to the repository's `fossgit` file in a directory in your execution
13
+ path, add its location in this repository to your execution path, or execute it
14
+ by entering the explicit path to the `fossgit` file at a shell prompt.
15
+
16
+ ## Usage
17
+
18
+ With an open checkout of your Fossil repository:
19
+
20
+ $ cd /path/to/open/fossil/checkout
21
+ $ fossgit /path/to/git/repository
22
+
23
+ ## Dependencies
24
+
25
+ * Fossil SCM
26
+ * Git
27
+ * a Fossil repository to mirror
28
+ * a Git repository you will use as your mirror
29
+ * an open checkout of the Fossil repository
30
+
31
+ ## Bug Reports And Feature Requests
32
+
33
+ In order from most preferred to least preferred:
34
+
35
+ * Add a ticket in the Fossil repository.
36
+ * Add a ticket in the GitHub repository (then I'll copy it to Fossil).
37
+
38
+ ## Roadmap
39
+
40
+ * Make this a stand-alone Ruby Gem some day, maybe.
41
+ * Add tests, maybe.
42
+ * Add automatic GitHub publishing, maybe.
43
+ * Incorporate this functionality into FossRec, a more comprehensive tool.
44
+
45
+ ## Development
46
+
47
+ The discerning programmer may look over FossGit in its current form and realize
48
+ it is neither object-oriented nor functional in its design. It is, in fact, a
49
+ pretty straightforward procedural program, written in Ruby (an odd language to
50
+ use for procedural programming, perhaps). The reason for this is simple: it is
51
+ in essence a glorified shell script. There are plans to make it part of a
52
+ larger set of libraries and utilities (see the Roadmap), and it will need to
53
+ undergo a fair bit of redesign as part of that; I expect it to be largely
54
+ unrecognizable by then.
55
+
56
+ Much of this work was done on Christmas weekend 2016. That may or may not be
57
+ significant.
data/bin/fossgit ADDED
@@ -0,0 +1,158 @@
1
+ #!/usr/bin/env ruby
2
+ require 'fossgit'
3
+
4
+ @fossil_repository = nil
5
+
6
+ def mirror_command
7
+ [fossil_command, sed_command, git_command].join '|'
8
+ end
9
+
10
+ def sed_command
11
+ %q{sed 's/^\(committer \+\)\([^ ]\+@[^ ]\+\)\( *<\)\(\w\+\)\(>.*\)$/\1\4\3\2\5/'}
12
+ end
13
+
14
+ def fossil_command
15
+ cmd = ['fossil export --git']
16
+
17
+ cmd << "--import-marks #{fossil_marks}" if update_export?
18
+ cmd << "--export-marks #{fossil_marks}"
19
+ cmd << fossil_repository
20
+
21
+ cmd.join ' '
22
+ end
23
+
24
+ def git_command
25
+ cmd = ['git fast-import']
26
+
27
+ cmd << "--import-marks=#{git_marks}" if update_export?
28
+ cmd << "--export-marks=#{git_marks}"
29
+
30
+ cmd.join ' '
31
+ end
32
+
33
+ def push_command
34
+ '; git checkout trunk; git push origin trunk'
35
+ end
36
+
37
+ def update_export?
38
+ File.exist? git_marks and File.exist? fossil_marks
39
+ end
40
+
41
+ def fossil_marks
42
+ fossil_file 'fossil.marks'
43
+ end
44
+
45
+ def git_marks
46
+ fossil_file 'git.marks'
47
+ end
48
+
49
+ def fossil_file filename
50
+ File.join fossil_path, filename
51
+ end
52
+
53
+ def fossil_path
54
+ get_option '-c' or Dir.pwd
55
+ end
56
+
57
+ def get_option opt, default=nil
58
+ ARGV.index(opt).tap do |val|
59
+ return val ? (ARGV.delete_at val and ARGV.delete_at val) : default
60
+ end
61
+ end
62
+
63
+ def option_switch? long_name
64
+ ARGV.delete "-#{long_name[0]}" or ARGV.delete "--#{long_name}"
65
+ end
66
+
67
+ def fossil_repository
68
+ idregex = /^repository: +/
69
+
70
+ @fossil_repository ||= File.absolute_path(
71
+ `fossil status`.split(/\n/).select do |line|
72
+ line.match idregex
73
+ end.first.sub idregex, ''
74
+ )
75
+ end
76
+
77
+ name = File.basename $0
78
+
79
+ help = <<-EOF
80
+
81
+ FossGit provides a simple tool for creating Git mirrors of Fossil
82
+ repositories. To use it, you need:
83
+
84
+ 1. both Fossil SCM and Git installed
85
+ 2. a Fossil repository to mirror with an open checkout
86
+ 3. a Git repository to use as a mirror
87
+
88
+ USAGE: #{name} -h
89
+ #{name} [-c <CHECKOUT>] [-l] <GITREPO>
90
+ #{name} -t
91
+
92
+ By default, when exporting to local Git repository GITREPO, #{name}
93
+ attempts to push updates to a configured upstream Git repository. It
94
+ harmlessly fails to push if no upstream repository is configured for the
95
+ local Git repository.
96
+
97
+ OPTIONS/ARGUMENTS:
98
+
99
+ -h Display this help text and exit, ignoring all other
100
+ arguments.
101
+
102
+ -c CHECKOUT Specify the location of your Fossil repository's open
103
+ checkout, CHECKOUT. This is optional; you may simply use
104
+ this tool from within an open checkout of your Fossil
105
+ repository instead.
106
+
107
+ -l Perform local-only mirror operations, without trying to
108
+ push Git updates to a remote repository. By default,
109
+ #{name} tries to push to an upstream Git repository
110
+ whenever it exports from Fossil to Git.
111
+
112
+ -t Dump export to STDOUT rather than sending it to Git.
113
+ This overrides the `-l` option and GITREPO argument, if
114
+ present.
115
+
116
+ GITREPO Specify the location of your local Git repository.
117
+
118
+ EXAMPLES:
119
+
120
+ $ fossgit -h
121
+
122
+ $ fossgit -c ~/fossil_checkouts/projectname ~/git/projectname
123
+
124
+ $ cd ~/fossil_checkouts/projectname && fossgit ~/git/projectname
125
+
126
+ EOF
127
+
128
+ if option_switch? 'help'
129
+ puts help
130
+ exit
131
+ elsif option_switch? 'version'
132
+ puts [name, FossGit.version].join ' '
133
+ elsif option_switch? 'text-export'
134
+ puts `#{fossil_command}|#{sed_command}`
135
+ exit
136
+ else
137
+ command_line = mirror_command
138
+ command_line << push_command unless option_switch? 'local'
139
+
140
+ git_path = ARGV.shift
141
+
142
+ if git_path.to_s.empty?
143
+ STDERR.puts 'Error! No Git path provided.'
144
+ exit!
145
+ elsif Dir.exist? git_path
146
+ Dir.chdir git_path
147
+ else
148
+ STDERR.puts %Q{Error! Invalid Git path "#{git_path}" provided.}
149
+ exit!
150
+ end
151
+
152
+ if system 'git status'
153
+ system command_line
154
+ else
155
+ STDERR.print %Q{Error! Invalid Git repository "#{Dir.pwd}" provided.}
156
+ exit!
157
+ end
158
+ end
data/lib/fossgit.rb ADDED
@@ -0,0 +1,5 @@
1
+ class FossGit
2
+ def self.version
3
+ '1.0.0'
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fossgit
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Chad Perrin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-12-25 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: |2
14
+ Maintain a presence in Git hosting for Fossil projects.
15
+ email: code@apotheon.net
16
+ executables:
17
+ - fossgit
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - LICENSE
22
+ - README.md
23
+ - bin/fossgit
24
+ - lib/fossgit.rb
25
+ homepage: https://fossrec.com/u/apotheon/fossgit
26
+ licenses:
27
+ - COIL
28
+ metadata: {}
29
+ post_install_message: |2
30
+ Thank you for using FossGit. For it to work properly, you need to have the
31
+ following software dependencies installed:
32
+
33
+ * Fossil SCM (the world's most decentralized SCM and DVCS)
34
+ * Git (the world's most popular DVCS)
35
+ * sed (standard on Unix-like systems)
36
+
37
+ Run "fossgit -h" for usage information.
38
+
39
+ Version 1.0.0 of FossGit is dedicated to my wife. Happy holidays.
40
+ rdoc_options: []
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 1.9.3
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ requirements: []
54
+ rubyforge_project:
55
+ rubygems_version: 2.4.5.1
56
+ signing_key:
57
+ specification_version: 4
58
+ summary: 'FossGit: Mirror Fossil to Git.'
59
+ test_files: []