Module: Nextgen::Actions::Git
- Included in:
- Nextgen::Actions
- Defined in:
- lib/nextgen/actions/git.rb
Instance Method Summary collapse
- #apply_as_git_commit(path, message: nil) ⇒ Object
- #git_commit_all(msg) ⇒ Object
-
#git_status ⇒ Object
Returns :clean, :dirty, or :error.
- #git_user_configured? ⇒ Boolean
- #git_working? ⇒ Boolean
- #say_git(message) ⇒ Object
Instance Method Details
#apply_as_git_commit(path, message: nil) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/nextgen/actions/git.rb', line 15 def apply_as_git_commit(path, message: nil) say , :cyan if @commit_messages = [] initially_clean = git_working? && git_status == :clean say_status :apply, File.basename(path) apply path, verbose: false return if !initially_clean || git_status == :clean commit = &.dup || "Apply #{File.basename(path)} generator from nextgen" commit << ("\n\n- " + @commit_messages.join("\n- ")) unless @commit_messages.empty? git_commit_all(commit) ensure @commit_messages = nil end |
#git_commit_all(msg) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/nextgen/actions/git.rb', line 30 def git_commit_all(msg) tmp_file = File.join(Dir.tmpdir, "nextgen_git_message_#{SecureRandom.hex(8)}.rb") File.write(tmp_file, msg.rstrip + "\n") git add: ".", commit: "-F #{tmp_file.shellescape}" end |
#git_status ⇒ Object
Returns :clean, :dirty, or :error
49 50 51 52 53 54 55 56 |
# File 'lib/nextgen/actions/git.rb', line 49 def git_status return :error unless Dir.exist?(".git") output, status = Open3.capture2e("git status --porcelain") return :error unless status.success? output.empty? ? :clean : :dirty end |
#git_user_configured? ⇒ Boolean
43 44 45 46 |
# File 'lib/nextgen/actions/git.rb', line 43 def git_user_configured? out, status = Open3.capture2e("git config -l") status.success? && out.match?(/^user\.name=/) && out.match?(/^user\.email=/) end |
#git_working? ⇒ Boolean
37 38 39 40 41 |
# File 'lib/nextgen/actions/git.rb', line 37 def git_working? return @git_working if defined?(@git_working) @git_working = git_status != :error && git_user_configured? end |
#say_git(message) ⇒ Object
10 11 12 13 |
# File 'lib/nextgen/actions/git.rb', line 10 def say_git() @commit_messages << if @commit_messages say , :cyan end |