Page 1 of 1

Git Updater Script

Posted: Sat Feb 25, 2017 20:39
by bell07
Since I use mods, I install them most from git repositories. I like maintained software and I do not like to do it by self :-)
To get all the repositories in sync I am to lazy, so I has written an update script for me.

The script does work on linux, I use it with bash shell. Maybe it is usable on windows with cygwin-bash, but I did not tested it, I do not use the W$.

The script does search from current directory trough all sub-directories for git-managed repos (".git" exists) and take the git-magic. Initial working support for ".hg" is included, but I do not have currently any mercurial repos.

How to use:

Code: Select all

cd ~/.minetest
sh 9
The number is log-level. 0-3 is implemented, but I use mostly 9 or 99 on command line, don't ask me why .

The script:

Code: Select all

~/.minetest $ cat 

Code: Select all



if  [ "$VERBOSE" == "" ]; then

# 0: just update relevant infos
# 1 display "branch -vaa" + local changes
# 2 display log on current branch
# 3 display "remote -v"

find . -name ".git" -type d | while read repo; do
   echo ''
   echo '--------------------------------------'
   echo "$(dirname "$repo")"
   echo '--------------------------------------'

   cd "$(dirname "$repo")"

# fetch all connected remotes
   for repo in $(git remote); do
      git fetch "$repo" --prune

# Display repo status in different verbosity
   if [ "$VERBOSE" -ge 1 ]; then
      git branch -vva

# create log range
   currentbranch="$(git branch | grep '^*' | sed 's:\* ::g')"
   remotebranch="$(git branch -avv | grep '^\*' | sed 's@.*\[@@g;s@[]:].*@@g' | grep -v '^\*')"

# print the log information
   if [ "$VERBOSE" -ge 2 ]; then
      if [ "$remotebranch" == "" ]; then
         echo '!!!!! No remote branch for' $currentbranch '!!!!!!'
         echo $currentbranch '=>' "$remotebranch"
         git --no-pager log  $currentbranch..$remotebranch

      if [ "$VERBOSE" -ge 3 ]; then
         git remote -v

# Now pull+merge
#   git pull. (from man git-pull: git pull is shorthand for git fetch followed by git merge FETCH_HEAD.)
   if [ ! "$remotebranch" == "" ]; then
      git merge "$remotebranch"

# display local changes
   if [ $VERBOSE -ge 1 ]; then
	   git --no-pager diff #display local changes

   echo "last commit: $(git log -1 --format=%cd)"

   cd - >/dev/null

# Find all ".hg" and pull them
find . -name ".hg" -type d | while read repo; do
   echo "$(dirname "$repo")"
   cd "$(dirname "$repo")"
   hg pull
   cd - >/dev/null

Re: Git Updater Script

Posted: Sun Feb 26, 2017 18:36
by Linuxdirk
bell07 wrote:To get all the repositories in sync I am to lazy, so I has written an update script for me.
I did the same. Not as complex as yours and no automatic detection (because I have Git managed stuff there I don’t want to be updated because I am the maintainer by myself).

Code: Select all

#! /usr/bin/env luajit

local basedir = '/home/USERNAME/.minetest/mods/'

local mods = {

print('Updating '..#mods..' mods\n')

for i,mod in pairs(mods) do
    print('---------------------------------------------\n'..'Processing '..mod)
    os.execute('git -C '..basedir..mod..' pull')
Just change basedir to where your mods are located, add your mods to the mods table and run the script.

Re: Git Updater Script

Posted: Sat Apr 08, 2017 07:03
by bell07
Linuxdirk wrote:because I have Git managed stuff there I don’t want to be updated because I am the maintainer by myself
The great at the Git is it can handle this, from there my script can handle it too.
The script updates the repositories with remote branch (--set-upstream-to=) is set. So
- for current development if you work as usual on a local development branch, the script does not touch them.
- If you are maintainer and the sole contributor you get of course just no updates.
- If you take the changed directly on the master (like change rarity settings) you need to take a local commit for this. In this case all upstream changes will be merged without any conflicts in most cases.

I use the script on my growing mod collection once per day, mostly without any issues.

Re: Git Updater Script

Posted: Fri Apr 28, 2017 07:23
by bell07
Small update: added "--prune" option to "git fetch" to clean up removed remote branches.

Re: Git Updater Script

Posted: Sat Jun 03, 2017 09:59
by Merak

Re: Git Updater Script

Posted: Wed Jun 07, 2017 07:46
by bell07
My "Rollout" script in addition: pull all repos on 1 system and then copy it to other systems. The git history is not copied to other systems.

Code: Select all

RSYNC_PARAM="--recursive --links --safe-links --perms --times"
RSYNC_PARAM="$RSYNC_PARAM -v --omit-dir-times --compress --force --whole-file --delete"
RSYNC_PARAM="$RSYNC_PARAM --stats --human-readable --timeout=180"
RSYNC_PARAM="$RSYNC_PARAM --exclude [.]git/"
rsync $RSYNC_PARAM "$MT_REMOTE"/mods  "$MT_REMOTE"/games "$MT_LOCAL"

Re: Git Updater Script

Posted: Fri Jul 21, 2017 17:24
by sreq

Code: Select all

import os

mpath = os.path.expanduser("~")+"/.minetest"
mmods = os.path.join(mpath, "mods")
mclientmods = os.path.join(mpath, "clientmods")
mgames = os.path.join(mpath, "games")

def getGit(path, c):
	r = ""
	g = os.popen("git -C "+path+" "+c, "r")
	while 1:
		line = g.readline()
		if not line: break
	return r[:-1]

def UpdateDir(path):
	if not os.path.exists(path):
	for file in os.listdir(path):
		dpath = os.path.join(path, file)
		if(os.path.isdir(os.path.join(dpath, ".git"))):
			r = getGit(dpath, "remote")
			os.system("git -C "+dpath+" pull "+r+" master")