Sha256: 6e692b7fdffd9a7329ef698f6db651c618889693fd71f807a1a8b963b98371ec

Contents?: true

Size: 1.17 KB

Versions: 31

Compression:

Stored size: 1.17 KB

Contents

# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2021-2023, by Samuel Williams.

require 'bake/modernize'

def git
	update(root: Dir.pwd)
end

def update(root:)
	if current_branch == "master"
		# https://github.com/github/renaming
		system("git", "branch", "-M", "main")
		system("git", "push", "-u", "origin", "main")
	end
	
	current_gitignore_custom_lines = self.current_gitignore_custom_lines(root)
	
	template_root = Bake::Modernize.template_path_for('git')
	Bake::Modernize.copy_template(template_root, root)
	
	if current_gitignore_custom_lines
		File.open(File.join(root, ".gitignore"), "a") do |file|
			file.puts
			file.puts(current_gitignore_custom_lines)
		end
	end
end

private

def current_gitignore_custom_lines(root)
	gitignore_path = File.join(root, ".gitignore")
	
	if File.exist?(gitignore_path)
		lines = File.readlines(gitignore_path)
		if blank_index = lines.index{|line| line =~ /^\s*$/}
			lines.shift(blank_index+1)
			return lines
		end
	end
end

def current_branch
	require 'open3'
	
	output, status = Open3.capture2("git", "branch", "--show-current")
	
	unless status.success?
		raise "Could not get current branch!"
	end
	
	return output
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
bake-modernize-0.29.0 bake/modernize/git.rb
bake-modernize-0.28.0 bake/modernize/git.rb
bake-modernize-0.27.3 bake/modernize/git.rb
bake-modernize-0.27.2 bake/modernize/git.rb
bake-modernize-0.27.1 bake/modernize/git.rb
bake-modernize-0.27.0 bake/modernize/git.rb
bake-modernize-0.26.0 bake/modernize/git.rb
bake-modernize-0.25.0 bake/modernize/git.rb
bake-modernize-0.24.0 bake/modernize/git.rb
bake-modernize-0.23.0 bake/modernize/git.rb
bake-modernize-0.22.0 bake/modernize/git.rb
bake-modernize-0.21.0 bake/modernize/git.rb
bake-modernize-0.20.0 bake/modernize/git.rb
bake-modernize-0.19.4 bake/modernize/git.rb
bake-modernize-0.19.3 bake/modernize/git.rb
bake-modernize-0.19.2 bake/modernize/git.rb
bake-modernize-0.19.1 bake/modernize/git.rb
bake-modernize-0.19.0 bake/modernize/git.rb
bake-modernize-0.18.0 bake/modernize/git.rb
bake-modernize-0.17.8 bake/modernize/git.rb