diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9f11b75 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea/ diff --git a/.gitm.toml b/.gitm.toml new file mode 100644 index 0000000..6f47c75 --- /dev/null +++ b/.gitm.toml @@ -0,0 +1,3 @@ +[repos] +origin = "ssh://git@192.168.100.62:2222/Arsen6331/gitm.git" +gitlab = "git@gitlab.com:moussaelianarsen/gitm.git" diff --git a/README.md.o b/README.md.o new file mode 100644 index 0000000..f7f777a --- /dev/null +++ b/README.md.o @@ -0,0 +1,13 @@ +# Gitm +Automatic git mirroring script. + +### How it works +This is a simple script that intercepts commands like `git init` and `git push` and automatically configures and pushes to many different remotes. + +### Usage +To use this script, create a file called `.gitm.toml` and populate it with repositories like so: +```toml +[repos] +origin = "https://gitea.arsenm.dev/Arsen6331/gitm.git" +gitlab = "https://gitea.arsenm.dev/moussaelianarsen/gitm.git" +``` \ No newline at end of file diff --git a/gitm.rb b/gitm.rb new file mode 100644 index 0000000..8924b87 --- /dev/null +++ b/gitm.rb @@ -0,0 +1,41 @@ +#!/usr/bin/ruby + +require 'toml' +require 'colorize' + +args = ARGV +cfgName = ".gitm.toml" + +def log(str) + txt = "[gitm]".cyan + puts "#{txt} #{str}" +end + +File.open(cfgName, "a") {} unless File.exists? cfgName + +cfgData = TOML::Parser.new(File.read(cfgName)).parsed +repos = cfgData["repos"] || {} +branch = cfgData["defaultBranch"] || "master" +if repos["origin"].nil? + log "Error: origin repo required" + exit 1 +end + +if repos.length < 1 + puts "Please add repos to the #{cfgName} file" + exit 1 +end + +case args[0] +when "push" + log "Intercepted push command" + repos.each { |name, _| system "git push #{name} #{branch}" } +when "init" + log "Intercepted init command" + system "git init" + repos.each { |name, repo| system "git remote add #{name} #{repo}" } + system "git fetch origin" + system "git checkout master" +else + system "git", *args +end \ No newline at end of file