@kova1/pullr 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +72 -0
- package/bin/pullr +115 -0
- package/package.json +40 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Max Koval
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# pullr
|
|
2
|
+
|
|
3
|
+
Fast-forward pull every git repository under a directory.
|
|
4
|
+
|
|
5
|
+
Built for workspaces made of many independent repositories, where keeping
|
|
6
|
+
everything current means `cd`-ing into each one.
|
|
7
|
+
|
|
8
|
+
```console
|
|
9
|
+
$ pullr ~/work
|
|
10
|
+
+ api (main, 3 new commit(s))
|
|
11
|
+
= web (main)
|
|
12
|
+
- scratch (main has no upstream)
|
|
13
|
+
x infra (main)
|
|
14
|
+
fatal: Not possible to fast-forward, aborting.
|
|
15
|
+
|
|
16
|
+
Repos: 4 updated: 1 up to date: 1 skipped: 1 failed: 1
|
|
17
|
+
Failed: infra
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Install
|
|
21
|
+
|
|
22
|
+
```sh
|
|
23
|
+
# Homebrew
|
|
24
|
+
brew install kova1max/tap/pullr # after that, plain `pullr` works too
|
|
25
|
+
|
|
26
|
+
# npm
|
|
27
|
+
npm install -g @kova1/pullr
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Or copy [`bin/pullr`](bin/pullr) anywhere on your `PATH` - it is a single bash
|
|
31
|
+
script with no dependencies beyond `git`.
|
|
32
|
+
|
|
33
|
+
## Usage
|
|
34
|
+
|
|
35
|
+
```
|
|
36
|
+
pullr [--max-depth N] [DIR]
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
| Option | Default | Meaning |
|
|
40
|
+
| --- | --- | --- |
|
|
41
|
+
| `DIR` | current directory | Where to look for repositories |
|
|
42
|
+
| `--max-depth N` | `2` | How many directory levels below `DIR` to search. `0` = only `DIR` itself, `1` = `DIR` and its direct children, ... |
|
|
43
|
+
| `-V`, `--version` | | Print the version |
|
|
44
|
+
| `-h`, `--help` | | Show help |
|
|
45
|
+
|
|
46
|
+
Behaviour:
|
|
47
|
+
|
|
48
|
+
- Runs `git pull --ff-only`, so it never creates merge commits. A branch that
|
|
49
|
+
has diverged from its upstream is reported as failed and left untouched.
|
|
50
|
+
- Does not descend into a repository once found - nested repositories and
|
|
51
|
+
submodules are left to their parent.
|
|
52
|
+
- Skips repositories on a detached `HEAD` and branches with no upstream.
|
|
53
|
+
- Does not follow symlinked directories.
|
|
54
|
+
- Exits `1` if any pull failed, `2` on invalid arguments, `0` otherwise.
|
|
55
|
+
|
|
56
|
+
Each repository gets one line: `+` updated, `=` already up to date, `-`
|
|
57
|
+
skipped, `x` failed (with git's output indented below it).
|
|
58
|
+
|
|
59
|
+
## Development
|
|
60
|
+
|
|
61
|
+
```sh
|
|
62
|
+
npm install # installs bats
|
|
63
|
+
npm test # end-to-end tests against real temporary git repos
|
|
64
|
+
npm run lint # shellcheck
|
|
65
|
+
PULLR_BASH=/bin/bash npm test # run the suite under macOS's bash 3.2
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Releases are cut by GitHub Actions - see [RELEASE.md](RELEASE.md).
|
|
69
|
+
|
|
70
|
+
## License
|
|
71
|
+
|
|
72
|
+
[MIT](LICENSE)
|
package/bin/pullr
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Recursively find git repos under a directory and fast-forward pull each one.
|
|
3
|
+
# Usage: pullr [--max-depth N] [DIR]
|
|
4
|
+
set -euo pipefail
|
|
5
|
+
|
|
6
|
+
VERSION="0.1.0" # set by the release workflow
|
|
7
|
+
|
|
8
|
+
usage() {
|
|
9
|
+
cat <<'EOF'
|
|
10
|
+
Usage: pullr [--max-depth N] [DIR]
|
|
11
|
+
|
|
12
|
+
Finds git repositories under DIR (default: current directory) and runs
|
|
13
|
+
`git pull --ff-only` in each. Does not descend into a repository once found.
|
|
14
|
+
|
|
15
|
+
Options:
|
|
16
|
+
--max-depth N How many directory levels below DIR to search (default: 2).
|
|
17
|
+
0 = only DIR itself, 1 = DIR and its direct children, ...
|
|
18
|
+
-V, --version Print the version.
|
|
19
|
+
-h, --help Show this help.
|
|
20
|
+
EOF
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
max_depth=2
|
|
24
|
+
root=""
|
|
25
|
+
|
|
26
|
+
while (($#)); do
|
|
27
|
+
case "$1" in
|
|
28
|
+
--max-depth) max_depth="${2:-}"; shift 2 || { usage >&2; exit 2; } ;;
|
|
29
|
+
--max-depth=*) max_depth="${1#*=}"; shift ;;
|
|
30
|
+
-h|--help) usage; exit 0 ;;
|
|
31
|
+
-V|--version) echo "pullr $VERSION"; exit 0 ;;
|
|
32
|
+
-*) echo "Unknown option: $1" >&2; usage >&2; exit 2 ;;
|
|
33
|
+
*)
|
|
34
|
+
[[ -z "$root" ]] || { echo "Only one DIR allowed" >&2; exit 2; }
|
|
35
|
+
root="$1"; shift ;;
|
|
36
|
+
esac
|
|
37
|
+
done
|
|
38
|
+
|
|
39
|
+
[[ "$max_depth" =~ ^[0-9]+$ ]] || { echo "--max-depth must be a non-negative integer" >&2; exit 2; }
|
|
40
|
+
root="${root:-.}"
|
|
41
|
+
[[ -d "$root" ]] || { echo "Not a directory: $root" >&2; exit 2; }
|
|
42
|
+
root="$(cd "$root" && pwd)"
|
|
43
|
+
|
|
44
|
+
if [[ -t 1 ]]; then
|
|
45
|
+
green=$'\e[32m' yellow=$'\e[33m' red=$'\e[31m' dim=$'\e[2m' reset=$'\e[0m'
|
|
46
|
+
else
|
|
47
|
+
green="" yellow="" red="" dim="" reset=""
|
|
48
|
+
fi
|
|
49
|
+
|
|
50
|
+
updated=0 current=0 skipped=0 failed=0
|
|
51
|
+
failed_repos=()
|
|
52
|
+
|
|
53
|
+
pull_repo() {
|
|
54
|
+
local repo="$1" rel="${1#"$root"}"
|
|
55
|
+
rel="${rel#/}"; rel="${rel:-.}"
|
|
56
|
+
|
|
57
|
+
local branch
|
|
58
|
+
if ! branch="$(git -C "$repo" symbolic-ref --quiet --short HEAD)"; then
|
|
59
|
+
printf '%s-%s %s %s(detached HEAD)%s\n' "$yellow" "$reset" "$rel" "$dim" "$reset"
|
|
60
|
+
skipped=$((skipped + 1)); return
|
|
61
|
+
fi
|
|
62
|
+
if ! git -C "$repo" rev-parse --quiet --verify '@{upstream}' >/dev/null 2>&1; then
|
|
63
|
+
printf '%s-%s %s %s(%s has no upstream)%s\n' "$yellow" "$reset" "$rel" "$dim" "$branch" "$reset"
|
|
64
|
+
skipped=$((skipped + 1)); return
|
|
65
|
+
fi
|
|
66
|
+
|
|
67
|
+
local before after out
|
|
68
|
+
before="$(git -C "$repo" rev-parse HEAD)"
|
|
69
|
+
if ! out="$(git -C "$repo" pull --ff-only 2>&1)"; then
|
|
70
|
+
printf '%sx%s %s %s(%s)%s\n' "$red" "$reset" "$rel" "$dim" "$branch" "$reset"
|
|
71
|
+
printf ' %s\n' "${out//$'\n'/$'\n' }"
|
|
72
|
+
failed=$((failed + 1)); failed_repos+=("$rel"); return
|
|
73
|
+
fi
|
|
74
|
+
after="$(git -C "$repo" rev-parse HEAD)"
|
|
75
|
+
|
|
76
|
+
if [[ "$before" == "$after" ]]; then
|
|
77
|
+
printf '%s=%s %s %s(%s)%s\n' "$dim" "$reset" "$rel" "$dim" "$branch" "$reset"
|
|
78
|
+
current=$((current + 1))
|
|
79
|
+
else
|
|
80
|
+
local n
|
|
81
|
+
n="$(git -C "$repo" rev-list --count "$before..$after")"
|
|
82
|
+
printf '%s+%s %s %s(%s, %s new commit(s))%s\n' "$green" "$reset" "$rel" "$dim" "$branch" "$n" "$reset"
|
|
83
|
+
updated=$((updated + 1))
|
|
84
|
+
fi
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
walk() {
|
|
88
|
+
local dir="$1" depth="$2"
|
|
89
|
+
if [[ -e "$dir/.git" ]]; then
|
|
90
|
+
pull_repo "$dir"
|
|
91
|
+
return
|
|
92
|
+
fi
|
|
93
|
+
((depth < max_depth)) || return 0
|
|
94
|
+
local child
|
|
95
|
+
for child in "$dir"/*/; do
|
|
96
|
+
[[ -d "$child" && ! -L "${child%/}" ]] || continue
|
|
97
|
+
walk "${child%/}" $((depth + 1))
|
|
98
|
+
done
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
walk "$root" 0
|
|
102
|
+
|
|
103
|
+
total=$((updated + current + skipped + failed))
|
|
104
|
+
if ((total == 0)); then
|
|
105
|
+
echo "No git repositories found under $root (max depth $max_depth)"
|
|
106
|
+
exit 0
|
|
107
|
+
fi
|
|
108
|
+
|
|
109
|
+
echo
|
|
110
|
+
printf 'Repos: %d %supdated: %d%s up to date: %d %sskipped: %d%s %sfailed: %d%s\n' \
|
|
111
|
+
"$total" "$green" "$updated" "$reset" "$current" "$yellow" "$skipped" "$reset" "$red" "$failed" "$reset"
|
|
112
|
+
if ((failed)); then
|
|
113
|
+
printf 'Failed: %s\n' "${failed_repos[*]}"
|
|
114
|
+
exit 1
|
|
115
|
+
fi
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kova1/pullr",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Fast-forward pull every git repository under a directory",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"git",
|
|
7
|
+
"pull",
|
|
8
|
+
"cli",
|
|
9
|
+
"monorepo",
|
|
10
|
+
"workspace"
|
|
11
|
+
],
|
|
12
|
+
"homepage": "https://github.com/kova1max/pullr#readme",
|
|
13
|
+
"bugs": "https://github.com/kova1max/pullr/issues",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/kova1max/pullr.git"
|
|
17
|
+
},
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"author": "Max Koval <kova1max99@gmail.com>",
|
|
20
|
+
"bin": {
|
|
21
|
+
"pullr": "bin/pullr"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"bin/pullr"
|
|
25
|
+
],
|
|
26
|
+
"os": [
|
|
27
|
+
"darwin",
|
|
28
|
+
"linux"
|
|
29
|
+
],
|
|
30
|
+
"scripts": {
|
|
31
|
+
"lint": "shellcheck bin/pullr",
|
|
32
|
+
"test": "bats test"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"bats": "^1.13.0"
|
|
36
|
+
},
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"access": "public"
|
|
39
|
+
}
|
|
40
|
+
}
|