From fdef03a6176461256ad2b165008131d63582add9 Mon Sep 17 00:00:00 2001 From: Patrick Spek Date: Wed, 8 Mar 2023 10:04:12 +0100 Subject: Split pull functionality into its own subcommand --- CHANGELOG.md | 2 ++ lib/main.bash | 6 ++++-- lib/subcommands/pull.bash | 15 +++++++++++++++ lib/subcommands/sync.bash | 13 +++---------- 4 files changed, 24 insertions(+), 12 deletions(-) create mode 100644 lib/subcommands/pull.bash diff --git a/CHANGELOG.md b/CHANGELOG.md index 474c4a5..5156976 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - A `diff` subcommand has been added to show all non-committed changes. It is a convenience wrapper to avoid having to change directory and run `git diff` to get an overview of all pending changes. +- A `pull` subcommand has been added to only pull the latest changes into the + `$BASHTARD_ETCDIR`, without running `sync` on all the playbooks. ### Changed diff --git a/lib/main.bash b/lib/main.bash index 12033db..d8d4cc4 100644 --- a/lib/main.bash +++ b/lib/main.bash @@ -80,6 +80,7 @@ Usage: $BASHTARD_NAME diff $BASHTARD_NAME init [repository] $BASHTARD_NAME pkg + $BASHTARD_NAME pull $BASHTARD_NAME ssh $BASHTARD_NAME sync [playbook] $BASHTARD_NAME sysinfo @@ -90,10 +91,11 @@ Perform maintenance on your infra. Commands: add Add a configuration playbook to this machine. - init Initialize the $BASHTARD_NAME configuration system. - pkg Interface into the pkg abstraction used by $BASHTARD_NAME. del Remove a configuration playbook from this machine. diff Show a diff of all uncommitted changes. + init Initialize the $BASHTARD_NAME configuration system. + pkg Interface into the pkg abstraction used by $BASHTARD_NAME. + pull Pull the latest changes through git. ssh Run a given command on all known hosts. sync Pull latest changes through git, and synchronize all added playbooks. diff --git a/lib/subcommands/pull.bash b/lib/subcommands/pull.bash new file mode 100644 index 0000000..4061f1b --- /dev/null +++ b/lib/subcommands/pull.bash @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +# SPDX-FileCopyrightText: 2023 Patrick Spek +# +# SPDX-License-Identifier: AGPL-3.0-or-later + +subcommand() +{ + notice "bashtard/pull" "Pulling latest changes in $BASHTARD_ETCDIR" + + git -C "$BASHTARD_ETCDIR" stash + git -C "$BASHTARD_ETCDIR" pull origin master || return 4 + git -C "$BASHTARD_ETCDIR" submodule update --recursive --remote || return 4 + git -C "$BASHTARD_ETCDIR" stash pop +} diff --git a/lib/subcommands/sync.bash b/lib/subcommands/sync.bash index ed03faa..1ae2aae 100644 --- a/lib/subcommands/sync.bash +++ b/lib/subcommands/sync.bash @@ -1,6 +1,6 @@ #!/usr/bin/env bash -# SPDX-FileCopyrightText: 2022 Patrick Spek +# SPDX-FileCopyrightText: 2023 Patrick Spek # # SPDX-License-Identifier: AGPL-3.0-or-later @@ -15,15 +15,8 @@ subcommand() return fi - notice "bashtard/sync" "Syncing $BASHTARD_ETCDIR" - pushd -- "$BASHTARD_ETCDIR" > /dev/null || return 4 - - git stash - git pull origin master || return 4 - git submodule update --recursive --remote || return 4 - git stash pop - - popd > /dev/null || return 4 + # Pull latest changes + "$BASHTARD_BIN" pull # Run a sync for each registered playbook for this host while read -r playbook -- cgit v1.1