Initial Commit
This commit is contained in:
parent
32230463e8
commit
8b9d8c5b48
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
.idea/
|
3
.gitm.toml
Normal file
3
.gitm.toml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
[repos]
|
||||||
|
origin = "ssh://git@192.168.100.62:2222/Arsen6331/gitm.git"
|
||||||
|
gitlab = "git@gitlab.com:moussaelianarsen/gitm.git"
|
13
README.md.o
Normal file
13
README.md.o
Normal file
@ -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"
|
||||||
|
```
|
41
gitm.rb
Normal file
41
gitm.rb
Normal file
@ -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
|
Reference in New Issue
Block a user