Skip to content

Commit 332eb0b

Browse files
committed
Add more submodule tools
- Add `git-submodule-ls` - Add `git-submodule-paths` Signed-off-by: Joe Block <[email protected]>
1 parent f1d2929 commit 332eb0b

File tree

3 files changed

+104
-0
lines changed

3 files changed

+104
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ If you wrote one of these scripts and want it removed from this collection, plea
162162
| `git-sp` | A. Schwarz's [git-sp](https://github.com/Schwarzy1/git-sp) | "Simple push", single short command to commit, and push. Use `-a` flag to add all files to commit. |
163163
| `git-sr` | Noel Cower's [git-sr](https://gist.github.com/nilium/2829f6690ad888c25660c15ba3a7c59c) | Use `fzf` to switch to a different `git` ref. |
164164
| `git-stats` | Jake Zimmerman's [blog](https://blog.jez.io/cli-code-review/) | Displays stats for the files different between the current branch and `$REVIEW_BRANCH`, which if unset defaults to the repository's default branch. |
165+
| `git-submodule-ls` | | List all submodules in your project |
166+
| `git-submodule-paths` | `git-submodule --help` | Show path to all submodules in your checkout, with their current commit SHA |
165167
| `git-submodule-rm` | Greg V's [dotfiles](https://github.com/myfreeweb/dotfiles) & [Pascal Sommer](https://github.com/pascal-so/) | Allows you to remove a submodule easily with `git submodule-rm path/to/submodule`. |
166168
| `git-superpull` | Greg V's [vmware-archive/git_scripts](https://github.com/vmware-archive/git_scripts) | Pulls, then does a `git submodule init` and `git submodule update`. |
167169
| `git-switch-branch` | Andrew Steele's [dotfiles](https://github.com/Andrew565/dotfiles) | Make it easier to switch to a branch by a substring of its name. More useful if you are good about deleting branches which have been merged upstream and if your branch names include unique identifiers like ticket/issue numbers or feature names. |

bin/git-submodule-ls

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env bash
2+
#
3+
# List all submodules
4+
#
5+
# Copyright 2024, Joe Block <[email protected]>
6+
7+
set -o pipefail
8+
if [[ -n "$DEBUG" ]]; then
9+
# shellcheck disable=SC2086
10+
if [[ "$(echo $DEBUG | tr '[:upper:]' '[:lower:]')" == "verbose" ]]; then
11+
set -x
12+
fi
13+
fi
14+
15+
function debug() {
16+
if [[ -n "$DEBUG" ]]; then
17+
echo "$@"
18+
fi
19+
}
20+
21+
function echo-stderr() {
22+
echo "$@" 1>&2 ## Send message to stderr.
23+
}
24+
25+
function fail() {
26+
printf '%s\n' "$1" >&2 ## Send message to stderr. Exclude >&2 if you don't want it that way.
27+
exit "${2-1}" ## Return a code specified by $2 or 1 by default.
28+
}
29+
30+
function has() {
31+
# Check if a command is in $PATH
32+
which "$@" > /dev/null 2>&1
33+
}
34+
35+
function check-dependencies() {
36+
debug "Checking dependencies..."
37+
# shellcheck disable=SC2041
38+
# Placeholders for whatever programs you really need
39+
for p in 'git'
40+
do
41+
if ! has $p; then
42+
fail "Can't find $p in your $PATH"
43+
else
44+
debug "- Found $p"
45+
fi
46+
done
47+
}
48+
49+
check-dependencies
50+
51+
git submodule --quiet foreach --recursive 'echo $name'

bin/git-submodule-paths

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Show submodules and what commit they're at
4+
#
5+
# Copyright 2024, Joe Block <[email protected]>
6+
7+
set -o pipefail
8+
if [[ -n "$DEBUG" ]]; then
9+
# shellcheck disable=SC2086
10+
if [[ "$(echo $DEBUG | tr '[:upper:]' '[:lower:]')" == "verbose" ]]; then
11+
set -x
12+
fi
13+
fi
14+
15+
function debug() {
16+
if [[ -n "$DEBUG" ]]; then
17+
echo "$@"
18+
fi
19+
}
20+
21+
function echo-stderr() {
22+
echo "$@" 1>&2 ## Send message to stderr.
23+
}
24+
25+
function fail() {
26+
printf '%s\n' "$1" >&2 ## Send message to stderr. Exclude >&2 if you don't want it that way.
27+
exit "${2-1}" ## Return a code specified by $2 or 1 by default.
28+
}
29+
30+
function has() {
31+
# Check if a command is in $PATH
32+
which "$@" > /dev/null 2>&1
33+
}
34+
35+
function check-dependencies() {
36+
debug "Checking dependencies..."
37+
# shellcheck disable=SC2041
38+
# Placeholders for whatever programs you really need
39+
for p in 'git'
40+
do
41+
if ! has $p; then
42+
fail "Can't find $p in your $PATH"
43+
else
44+
debug "- Found $p"
45+
fi
46+
done
47+
}
48+
49+
check-dependencies
50+
51+
exec git submodule foreach 'echo $sm_path `git rev-parse HEAD`'

0 commit comments

Comments
 (0)