From 15ba9c8fb84094744288c84b1d1cdc1bb8d33096 Mon Sep 17 00:00:00 2001 From: Shulhan Date: Sun, 18 Sep 2022 01:49:23 +0700 Subject: all: add script git-update-all.sh This script fetch the latest commits from all git repositories under a directory. --- AUR/.SRCINFO | 2 +- AUR/PKGBUILD | 2 +- Makefile | 7 ++++--- README | 3 +++ bin/git-update-all.sh | 32 ++++++++++++++++++++++++++++++++ 5 files changed, 41 insertions(+), 5 deletions(-) create mode 100755 bin/git-update-all.sh diff --git a/AUR/.SRCINFO b/AUR/.SRCINFO index cffea12..0fe4509 100644 --- a/AUR/.SRCINFO +++ b/AUR/.SRCINFO @@ -1,6 +1,6 @@ pkgbase = bin.sh-git pkgdesc = A collection of shell scripts - pkgver = r2.23c8d78 + pkgver = r4.5a71a61 pkgrel = 1 arch = any license = GPL3 diff --git a/AUR/PKGBUILD b/AUR/PKGBUILD index c21e338..7b57586 100644 --- a/AUR/PKGBUILD +++ b/AUR/PKGBUILD @@ -1,6 +1,6 @@ # Maintainer: Shulhan pkgname=bin.sh-git -pkgver=r2.23c8d78 +pkgver=r4.5a71a61 pkgrel=1 pkgdesc="A collection of shell scripts" arch=('any') diff --git a/Makefile b/Makefile index 2956183..cc38f44 100644 --- a/Makefile +++ b/Makefile @@ -5,9 +5,10 @@ install: install -d $(DESTDIR)/usr/bin - install bin/chmod-x.sh $(DESTDIR)/usr/bin/ - install bin/tmux-session.sh $(DESTDIR)/usr/bin/ - install bin/wg-activate.sh $(DESTDIR)/usr/bin/ + install bin/chmod-x.sh $(DESTDIR)/usr/bin/ + install bin/git-update-all.sh $(DESTDIR)/usr/bin/ + install bin/tmux-session.sh $(DESTDIR)/usr/bin/ + install bin/wg-activate.sh $(DESTDIR)/usr/bin/ install -d $(DESTDIR)/etc/bash_completion.d install --mode=0644 etc/bash_completion.d/tmux-session $(DESTDIR)/etc/bash_completion.d/ diff --git a/README b/README index 855d1cb..4fd3a5f 100644 --- a/README +++ b/README @@ -8,6 +8,9 @@ A collection of shell scripts. Script to recursively scan directory and remove executable-bit from file that may not an executable. +*git-update-all.sh*:: +Script fetch the latest commits from all git repositories under a directory. + *tmux-session.sh*:: Script to open new tmux session with start directory based on configuration in `~/.tmux.session`. diff --git a/bin/git-update-all.sh b/bin/git-update-all.sh new file mode 100755 index 0000000..a786682 --- /dev/null +++ b/bin/git-update-all.sh @@ -0,0 +1,32 @@ +#!/bin/sh +## SPDX-FileCopyrightText: 2022 M. Shulhan +## SPDX-License-Identifier: GPL-3.0-or-later + +## Script to fetch the latest commits from all git repositories under a +## directory. +## +## Usage: +## +## $ git-update-all.sh $dir +## +## Where $dir is a path to directory that contains one or more repositories. + +DIR=${1:-.} + +echo "Updating all git repositories in $DIR" + +dirs=$(find -L "$DIR" -maxdepth 1 -mindepth 1 -type d -print) + +for repo in $dirs; do + if [[ ! -d "$repo/.git" ]]; then + continue + fi + + echo "" + echo ">>> updating $repo ..." + git -C $repo stash --quiet + git -C $repo pull --rebase + git -C $repo gc --prune=now --quiet + git -C $repo stash pop --quiet + git -C $repo fetch --prune --prune-tags +done -- cgit v1.3