aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2022-09-18 01:49:23 +0700
committerShulhan <ms@kilabit.info>2022-09-18 03:20:49 +0700
commit15ba9c8fb84094744288c84b1d1cdc1bb8d33096 (patch)
tree2f4da6b39336e2eb807eaf42cbb10c6e93fce60e
parent36bc0c7fb5df2b9dfebb9be153ccdea46c0b3d80 (diff)
downloadbin.sh-15ba9c8fb84094744288c84b1d1cdc1bb8d33096.tar.xz
all: add script git-update-all.sh
This script fetch the latest commits from all git repositories under a directory.
-rw-r--r--AUR/.SRCINFO2
-rw-r--r--AUR/PKGBUILD2
-rw-r--r--Makefile7
-rw-r--r--README3
-rwxr-xr-xbin/git-update-all.sh32
5 files changed, 41 insertions, 5 deletions
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 <ms@kilabit.info>
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 <ms@kilabit.info>
+## 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