Skip to content

Commit 8263978

Browse files
author
Nils Bars
committed
Add update sub command to ctrl.sh
1 parent 0f58bd5 commit 8263978

1 file changed

Lines changed: 25 additions & 2 deletions

File tree

ctrl.sh

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ $0 <Command> [OPTIONS...]
5050
Commands:
5151
build
5252
Build and pull all images including the docker based image.
53+
update
54+
Update the repository and all submodules.
5355
5456
up
5557
Start all serviceses.
@@ -287,12 +289,30 @@ if ! ./prepare.py; then
287289
exit 1
288290
fi
289291

290-
291-
function build {
292+
function update {
292293
(
294+
# Check for uncommitted changes, ignoring untracked files
295+
# -n tests if string length is non-zero
296+
# git status --porcelain -uno returns modified files (excluding untracked)
297+
if [[ -n "$(git status --porcelain -uno)" ]]; then
298+
error "There are uncommitted changes in the main repository. Please commit or stash them first."
299+
exit 1
300+
fi
301+
302+
# Check submodules for uncommitted changes, suppressing "Entering..." messages
303+
if [[ -n "$(git submodule foreach --quiet git status --porcelain -uno)" ]]; then
304+
error "There are uncommitted changes in one or more submodules. Please commit or stash them first."
305+
exit 1
306+
fi
307+
308+
info "=> Updating repository"
309+
git pull
293310
info "=> Updating submodules"
294311
git submodule update --recursive
295312
)
313+
}
314+
315+
function build {
296316
#Build the base image for all exercises
297317
(
298318
info "=> Building docker base image"
@@ -408,6 +428,9 @@ case "$cmd" in
408428
build)
409429
build "$@"
410430
;;
431+
update)
432+
update "$@"
433+
;;
411434
up)
412435
up "$@"
413436
;;

0 commit comments

Comments
 (0)