fossgit 1.1.0 → 1.2.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 +4 -4
  2. data/README.md +4 -1
  3. data/bin/fossgit +47 -32
  4. data/lib/fossgit.rb +14 -2
  5. data/lib/fossgit/cli.rb +50 -28
  6. metadata +4 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7eca5110eb895f6f749b936257f8afdc5319cfae
4
- data.tar.gz: 42265b429b00832cb61896d2479a7bc1ac352ff9
3
+ metadata.gz: 3c99282d257c6859651f8f047352af6af3b5baaf
4
+ data.tar.gz: 4f1054d869c6f7af44e259d9807b36cb52d8a9d4
5
5
  SHA512:
6
- metadata.gz: b020ff7cde1febd18476afe0f13fd84b1b910e80d717d40173a57e2be74a81ac4975e8293c64c146a1bd75bcdcef39e94dc58f872e6ae99d99aa06f5b484f45a
7
- data.tar.gz: 203a1b2366d7ac83e3d476a7af9e06679b691b4b75c7d9d208a66e9ec1a37f244254dfdbbc358a7a760514e89451cd1a059d625169be43d457a045bbde28486b
6
+ metadata.gz: 881a6fd0ce1c6e9f0b4592269fbb3060e044a0aa3a8ddecca4d2b1a6e26a344e13e5e546eff10d926c41ec4e2b15a638c48284b02fab657dd082965d5e783656
7
+ data.tar.gz: 7ed9257abb9763d7af0ab6895fc14e132376e335335cd51c17edfae43d09eb9474b8a1be00a7cf182c44baf4c8217f455c0759cc14daff45200b5d7b06e82205
data/README.md CHANGED
@@ -109,9 +109,12 @@ In order from most preferred to least preferred:
109
109
 
110
110
  ## Roadmap
111
111
 
112
- * Add more tests, maybe.
112
+ * Add autovivifying functionality for a local Git mirror.
113
+ * Add autovivifying functionality for GitHub and GitLab remotes.
114
+ * Add more tests.
113
115
  * Change defaults for v2.0, perhaps.
114
116
  * Incorporate this functionality into FossRec, a more comprehensive tool.
117
+ * Organize lib APIs and document them. (Don't rely on undocumented APIs.)
115
118
 
116
119
  [gem]: https://rubygems.org/gems/fossgit
117
120
  [frepo]: https://fossrec.com/u/apotheon/fossgit
@@ -1,66 +1,81 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'fossgit'
3
3
  require 'fossgit/cli'
4
- require 'yaml'
5
-
6
- def projectname
7
- fossil_info = YAML.load `fossil info | head -n 1`
8
- name = fossil_info ? fossil_info['project-name'] : fossil_info
9
- name if not name.eql? '<unnamed>'
10
- end
11
4
 
12
5
  @cli = CLI.new ARGV, File.basename($0)
13
- @fg = FossGit.new (@cli.get_option('-c') or Dir.pwd)
6
+ @fg = FossGit.new (@cli.get_option('checkout') or Dir.pwd)
14
7
 
15
8
  Dir.chdir @fg.checkout_path
16
9
 
17
- if @cli.config['gitdir'] and projectname and not @cli.config['gitrepo']
18
- @cli.config['gitrepo'] = File.join(@cli.config['gitdir'], projectname)
10
+ if @cli.config['gitdir'] and @fg.project_name
11
+ @cli.config['gitrepo'] ||= File.join(@cli.config['gitdir'], @fg.project_name)
19
12
  end
20
13
 
21
- if @cli.option_switch? 'help'
14
+ @cli.parse_switches %w(all help local newgit text-export version)
15
+
16
+ if @cli.switches['help']
22
17
  puts @cli.help_text
23
18
  exit
24
- elsif @cli.option_switch? 'version'
25
- puts [@cli.name, FossGit.version].join ' '
26
- elsif @cli.option_switch? 'text-export'
19
+ elsif @cli.switches['version']
20
+ puts @cli.name + ' ' + FossGit.version
21
+ elsif @cli.switches['text-export']
27
22
  system @fg.text_export_command
28
23
  exit
29
24
  else
30
- opts = Hash.new
31
- opts[:local] = @cli.option_switch? 'local'
25
+ if remotes = @cli.get_option('remotes')
26
+ remotes = remotes.split ','
27
+ end
32
28
 
33
- @cli.remotes = nil if (opts[:all] = @cli.remotes.eql? 'all')
29
+ ### NO MORE OPTION PARSING
34
30
 
35
- @cli.option_switch?('all').tap {|v| opts[:all] ||= v }
31
+ gitrepo = (@cli.args.shift or @cli.config['gitrepo'])
36
32
 
37
- remotes = (@cli.get_option '-r') or @cli.remotes
33
+ unless remotes or @cli.switches['local']
34
+ if @cli.switches['all']
35
+ remotes = @fg.git_remotes(gitrepo)
36
+ elsif @cli.remotes and not @cli.switches['newgit']
37
+ remotes = (@cli.remotes == 'all') ? @fg.git_remotes(gitrepo) : @cli.remotes
38
+ else
39
+ remotes = ['origin']
40
+ end
41
+ end
38
42
 
39
- gitrepo = (@cli.args.shift or @cli.config['gitrepo'])
43
+ hasgit = Dir.exist? gitrepo
40
44
 
41
45
  if gitrepo.to_s.empty?
42
46
  STDERR.puts 'Error! No Git path provided.'
43
47
  exit!
44
- elsif Dir.exist? gitrepo
48
+ elsif @cli.switches['newgit'] and gitrepo
49
+ if hasgit
50
+ STDERR.puts %Q{Error! Directory "#{gitrepo}" already exists.}
51
+ exit!
52
+ elsif Dir.mkdir gitrepo
53
+ Dir.chdir(gitrepo)
54
+
55
+ if `git init`.empty?
56
+ STDERR.puts %{Error! Cannot init Git within "#{gitrepo}".}
57
+ exit!
58
+ end
59
+ else
60
+ STDERR.puts %Q{Error! Cannot create directory "#{gitrepo}".}
61
+ exit!
62
+ end
63
+ elsif @cli.switches['newgit']
64
+ STDERR.puts %Q{Error! Name for new Git repository unknown.}
65
+ exit!
66
+ elsif hasgit
45
67
  Dir.chdir gitrepo
46
68
  else
47
69
  STDERR.puts %Q{Error! Invalid Git path "#{gitrepo}" provided.}
48
70
  exit!
49
71
  end
50
72
 
51
- if remotes
52
- remotes = remotes.split ','
53
- else
54
- if opts[:all]
55
- remotes = @fg.git_remotes gitrepo
56
- else
57
- remotes = ['origin']
58
- end
59
- end
60
-
61
73
  if system 'git status'
62
- if opts[:local]
74
+ if @cli.switches['local']
63
75
  system @fg.mirror_command
76
+ elsif remotes.empty?
77
+ STDERR.print %Q{Error! Git repository "#{Dir.pwd}" has no remotes.}
78
+ exit!
64
79
  else
65
80
  @fg.push_remote_list! remotes
66
81
  end
@@ -1,16 +1,21 @@
1
+ require 'yaml'
2
+
1
3
  class FossGit
2
4
  attr_reader :checkout_path
3
5
  attr_reader :fossil_repository
6
+ attr_accessor :project_name
4
7
 
5
8
  def initialize checkout_path=''
6
9
  @checkout_path = checkout_path
7
10
  @checkout_path = get_element_matching :'local-root'
8
11
 
9
12
  @fossil_repository = get_repository_path
13
+
14
+ @project_name = get_project_name
10
15
  end
11
16
 
12
17
  def self.version
13
- '1.1.0'
18
+ '1.2.0'
14
19
  end
15
20
 
16
21
  def fossil_marks
@@ -45,6 +50,7 @@ class FossGit
45
50
  end
46
51
 
47
52
  def sed_command
53
+ # legacy fix for a bug in an old Fossil version's Git-export
48
54
  %q{sed 's/^\(committer \+\)\([^ ]\+@[^ ]\+\)\( *<\)\(\w\+\)\(>.*\)$/\1\4\3\2\5/'}
49
55
  end
50
56
 
@@ -79,6 +85,12 @@ class FossGit
79
85
 
80
86
  private
81
87
 
88
+ def get_project_name
89
+ fossil_info = YAML.load `fossil info | head -n 1`
90
+ name = fossil_info ? fossil_info['project-name'] : fossil_info
91
+ name if not name.eql? '<unnamed>'
92
+ end
93
+
82
94
  def get_repository_path
83
95
  File.absolute_path get_element_matching :repository
84
96
  end
@@ -94,7 +106,7 @@ class FossGit
94
106
  stat = `fossil status`
95
107
 
96
108
  if stat.size > 0
97
- stat.split(/\n/)
109
+ stat.split "\n"
98
110
  else
99
111
  raise ArgumentError, "#{checkout_path} is not a valid checkout path"
100
112
  end
@@ -1,7 +1,7 @@
1
1
  require 'yaml'
2
2
 
3
3
  class CLI
4
- attr_accessor :args, :config, :name
4
+ attr_accessor :args, :config, :name, :switches
5
5
 
6
6
  def initialize args=[], cliname='fossgit', filename='.fossgit'
7
7
  @args = args
@@ -12,6 +12,8 @@ class CLI
12
12
  @home_config_file = File.join(Dir.home, @config_filename)
13
13
 
14
14
  configure @config_filename
15
+
16
+ @switches = Hash.new
15
17
  end
16
18
 
17
19
  def configure file=@config_filename
@@ -51,7 +53,7 @@ class CLI
51
53
  3. a Git repository to use as a mirror
52
54
 
53
55
  USAGE: #{name} [-h | -v | -t]
54
- #{name} [-c <CHECKOUT>] [-a | -r REMOTE | -l] [GITREPO]
56
+ #{name} [-c <CHECKOUT>] [-a | -r REMOTE | -l] [[-n] GITREPO]
55
57
 
56
58
  By default, when exporting to local Git repository GITREPO, #{name}
57
59
  attempts to push updates to a configured upstream Git repository. It
@@ -62,37 +64,53 @@ class CLI
62
64
 
63
65
  OPTIONS/ARGUMENTS:
64
66
 
65
- -h Display this help text and exit, ignoring all other
66
- arguments.
67
+ -h | --help
68
+
69
+ Display this help text and exit, ignoring all other arguments.
70
+
71
+ -a | --all
72
+
73
+ Push to all configured remotes for the target Git repository.
74
+ Default is to push only to the configured "origin" remote.
75
+
76
+ -c <CHECKOUT> | --checkout <CHECKOUT>
67
77
 
68
- -a Push to all configured remotes for the target Git
69
- repository. Default behavior is to push only to the
70
- configured "origin" remote.
78
+ Specify CHECKOUT, your Fossil repository's checkout location.
79
+ This is optional; you may simply use this tool from within an
80
+ open checkout of your Fossil repository instead.
71
81
 
72
- -c CHECKOUT Specify the location of your Fossil repository's open
73
- checkout, CHECKOUT. This is optional; you may simply
74
- use this tool from within an open checkout of your
75
- Fossil repository instead.
82
+ -l | --local
76
83
 
77
- -l Perform local-only mirror operations, without trying
78
- to push Git updates to a remote repository. By
79
- default, #{name} tries to push to an upstream Git
80
- repository whenever it exports from Fossil to Git.
84
+ Perform local-only mirror operations without pushing to a remote
85
+ Git repository. By default, #{name} pushes to an upstream Git
86
+ repository whenever it exports from Fossil to Git.
81
87
 
82
- -r Specify which of your Git mirror's configured remotes
83
- you want to push. This overrides the -a switch. For
84
- multiple remotes, use a comma-separated list with no
85
- spaces between them.
88
+ -n | --newgit
89
+
90
+ Create a local Git repository mirror when it does not already
91
+ exist. Use this option from the Fossil repository's directory
92
+ hierarchy root and specify the Git repository's location as for
93
+ updating a mirror via config file, GITREPO argument, or Fossil
94
+ project-name setting in `fossil info` output.
86
95
 
87
- -t Dump export to STDOUT as text rather than sending it
88
- to Git. This overrides the `-l` switch and GITREPO
89
- argument, if present.
96
+ -r | --remotes <COMMA,SEPARATED,REMOTES>
90
97
 
91
- -v Show FossGit version number.
98
+ Specify which of the Git mirror's configured remotes to push in a
99
+ comma separated list with no spaces. This overrides `--all`.
92
100
 
93
- GITREPO Specify the location of your local Git repository.
94
- This is optional if there is a configuration file
95
- that specifies it for you.
101
+ -t | --text-export
102
+
103
+ Dump export to STDOUT as text rather than sending it to Git.
104
+ This overrides the `-l` switch and GITREPO argument, if present.
105
+
106
+ -v | --version
107
+
108
+ Show FossGit version number.
109
+
110
+ GITREPO
111
+
112
+ Specify the location of the local Git mirror, if there is no
113
+ configuration file specification or to override configuration.
96
114
 
97
115
  COMMAND EXAMPLES:
98
116
 
@@ -149,8 +167,8 @@ class CLI
149
167
  EOF
150
168
  end
151
169
 
152
- def get_option opt, default=nil
153
- if val = args.index(opt)
170
+ def get_option long_name, default=nil
171
+ if val = (args.index "-#{long_name[0]}" or args.index "--#{long_name}")
154
172
  return (args.delete_at val and args.delete_at val)
155
173
  else
156
174
  return default
@@ -160,4 +178,8 @@ class CLI
160
178
  def option_switch? long_name
161
179
  args.delete "-#{long_name[0]}" or args.delete "--#{long_name}"
162
180
  end
181
+
182
+ def parse_switches opts
183
+ opts.each {|opt| switches[opt] = option_switch? opt }
184
+ end
163
185
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fossgit
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chad Perrin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-20 00:00:00.000000000 Z
11
+ date: 2019-06-27 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: " Maintain a presence in Git hosting for Fossil project mirrors.\n"
14
14
  email: code@apotheon.net
@@ -34,9 +34,8 @@ post_install_message: |2
34
34
  * Git (the world's most popular DVCS)
35
35
  * sed (standard on Unix-like systems)
36
36
 
37
- This update adds support for configuration files and specifying which Git
38
- remotes to push. It should not break backward compatibility. If it does,
39
- that is a bug, and you are encouraged to report it at:
37
+ This update adds support for a full range of long options and for an option
38
+ to create a new local Git mirror on the fly. Please report bugs at:
40
39
 
41
40
  https://fossrec.com/u/apotheon/fossgit/index.cgi/reportlist
42
41