diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1df572a..7f22dfa 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,53 +8,57 @@ jobs: steps: - uses: actions/checkout@v4 - run: sudo apt-get install bash + - run: sudo apt-get remove git - run: ./.github/workflows/build.sh bash "" - bash-cvs: + bash-everything: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - run: sudo apt-get install bash cvs - - run: ./.github/workflows/build.sh bash "cvs" + - run: sudo apt-get install bash cvs git + - run: ./.github/workflows/build.sh bash "cvs git" dash-nothing: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - run: sudo apt-get install dash + - run: sudo apt-get remove git - run: ./.github/workflows/build.sh dash "" - dash-cvs: + dash-everything: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - run: sudo apt-get install dash cvs - - run: ./.github/workflows/build.sh dash "cvs" + - run: sudo apt-get install dash cvs git + - run: ./.github/workflows/build.sh dash "cvs git" mksh-nothing: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - run: sudo apt-get install mksh + - run: sudo apt-get remove git - run: ./.github/workflows/build.sh ksh "" - mksh-cvs: + mksh-everything: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - run: sudo apt-get install mksh cvs - - run: ./.github/workflows/build.sh ksh "cvs" + - run: sudo apt-get install mksh cvs git + - run: ./.github/workflows/build.sh ksh "cvs git" zsh-nothing: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - run: sudo apt-get install zsh + - run: sudo apt-get remove git - run: ./.github/workflows/build.sh zsh "" - zsh-cvs: + zsh-everything: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - run: sudo apt-get install zsh cvs - - run: ./.github/workflows/build.sh zsh "cvs" + - run: sudo apt-get install zsh cvs git + - run: ./.github/workflows/build.sh zsh "cvs git" diff --git a/Makefile.am b/Makefile.am index 8fdeb7f..529ec06 100644 --- a/Makefile.am +++ b/Makefile.am @@ -40,6 +40,7 @@ dist_pkgdata_DATA += cli.subr dist_pkgdata_DATA += config.subr dist_pkgdata_DATA += cvs.subr dist_pkgdata_DATA += fs.subr +dist_pkgdata_DATA += git.subr dist_pkgdata_DATA += hw.subr dist_pkgdata_DATA += list.subr dist_pkgdata_DATA += process.subr @@ -123,6 +124,10 @@ dist_man_MANS += man/shtk_cvs_update.3 dist_man_MANS += man/shtk_fs.3 dist_man_MANS += man/shtk_fs_join_paths.3 dist_man_MANS += man/shtk_fs_normalize_path.3 +dist_man_MANS += man/shtk_git.3 +dist_man_MANS += man/shtk_git_clone.3 +dist_man_MANS += man/shtk_git_fetch.3 +dist_man_MANS += man/shtk_git_update.3 dist_man_MANS += man/shtk_hw.3 dist_man_MANS += man/shtk_hw_ncpus.3 dist_man_MANS += man/shtk_list.3 @@ -216,6 +221,13 @@ EXTRA_DIST += fs_test.sh fs_test: $(srcdir)/fs_test.sh shtk $(AM_V_GEN)name=fs_test; $(BUILD_TEST) +TESTS += git_test +check_SCRIPTS += git_test +CLEANFILES += git_test +EXTRA_DIST += git_test.sh +git_test: $(srcdir)/git_test.sh shtk + $(AM_V_GEN)name=git_test; $(BUILD_TEST) + TESTS += hw_test check_SCRIPTS += hw_test CLEANFILES += hw_test diff --git a/NEWS.md b/NEWS.md index a4fcf8b..b181462 100644 --- a/NEWS.md +++ b/NEWS.md @@ -20,6 +20,8 @@ Changes in version 1.8 * Migrated to using Automake to run shtk's own test suite instead of Kyua. +* Added support for git. + Changes in version 1.7 ---------------------- diff --git a/git.subr b/git.subr new file mode 100644 index 0000000..bc9b4f7 --- /dev/null +++ b/git.subr @@ -0,0 +1,69 @@ +# Copyright 2025 Julio Merino +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +shtk_import bool +shtk_import cli +shtk_import process + + +shtk_git_fetch() { + local repo="${1}"; shift + local branch="${1}"; shift + local directory="${1}"; shift + + if [ -d "${directory}" ]; then + shtk_git_update "${branch}" "${directory}" + else + shtk_git_clone "${repo}" "${branch}" "${directory}" + fi +} + + +shtk_git_clone() { + local repo="${1}"; shift + local branch="${1}"; shift + local directory="${1}"; shift + + [ ! -d "${directory}" ] || shtk_cli_error "Cannot clone into" \ + "${directory}; directory already exists" + shtk_process_run git clone -b "${branch}" "${repo}" \ + "${directory}" || shtk_cli_error "git clone failed" +} + + +shtk_git_update() { + local branch="${1}"; shift + local directory="${1}"; shift + + [ -d "${directory}" ] || shtk_cli_error "Cannot update ${directory};" \ + "directory does not exist" + + shtk_process_run -w "${directory}" git fetch origin "${branch}" \ + || shtk_cli_error "git update failed" + shtk_process_run -w "${directory}" git checkout "${branch}" \ + || shtk_cli_error "git update failed" + shtk_process_run -w "${directory}" git merge --ff-only "origin/${branch}" \ + || shtk_cli_error "git update failed" +} diff --git a/git_test.sh b/git_test.sh new file mode 100644 index 0000000..58629ab --- /dev/null +++ b/git_test.sh @@ -0,0 +1,226 @@ +# Copyright 2025 Julio Merino +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +shtk_import git +shtk_import unittest + + +one_time_setup() { + which git >/dev/null 2>&1 || exit 77 +} + + +# Creates a local git repository with a commit in a variety of branches. +# +# \param repo Path to the repository to create. +# \param master Name of the master branch to create. +# \param ... Name of the other branches to create. +init_git_repo() { + local repo="${1}"; shift + local master="${1}"; shift + + assert_command -o ignore -e ignore \ + git config --global user.email "fake@example.com" + assert_command -o ignore -e ignore \ + git config --global user.name "Fake User" + + assert_command -o ignore -e ignore mkdir -p "${repo}" + assert_command -o ignore -e ignore git init --bare -b "${master}" "${repo}" + + for branch in "${master}" "${@}"; do + assert_command -o ignore -e ignore git init -b "${branch}" tmp + echo "file in ${branch}" >tmp/file + assert_command -o ignore -e ignore -w tmp git add file + assert_command -o ignore -e ignore -w tmp git commit -m message file + assert_command -o ignore -e ignore -w tmp git remote add origin "${repo}" + assert_command -o ignore -e ignore -w tmp git push origin "${branch}" + rm -rf tmp + done +} + + +shtk_unittest_add_fixture fetch +fetch_fixture() { + setup() { + MOCK_GITREPO="$(pwd)/git" + init_git_repo "${MOCK_GITREPO}" master other + } + + + teardown() { + rm -rf "${MOCK_GITREPO}" + } + + + shtk_unittest_add_test master_branch + master_branch_test() { + shtk_git_fetch "${MOCK_GITREPO}" master dir + assert_file inline:"file in master\n" dir/file + + cp -rf dir dir2 + echo "second revision" >dir2/file + assert_command -o ignore -e ignore -w dir2 git commit -a -m message + assert_command -o ignore -e ignore -w dir2 git push + rm -rf dir2 + + shtk_git_fetch "${MOCK_GITREPO}" master dir + assert_file inline:"second revision\n" dir/file + } + + + shtk_unittest_add_test other_branch + other_branch_test() { + shtk_git_fetch "${MOCK_GITREPO}" other dir + assert_file inline:"file in other\n" dir/file + + cp -rf dir dir2 + echo "second revision" >dir2/file + assert_command -o ignore -e ignore -w dir2 git commit -a -m message + assert_command -o ignore -e ignore -w dir2 git push + rm -rf dir2 + + shtk_git_fetch "${MOCK_GITREPO}" other dir + assert_file inline:"second revision\n" dir/file + } + + + shtk_unittest_add_test switch_branches + switch_branches_test() { + shtk_git_fetch "${MOCK_GITREPO}" master dir + assert_file inline:"file in master\n" dir/file + + shtk_git_fetch "${MOCK_GITREPO}" other dir + assert_file inline:"file in other\n" dir/file + } +} + + +shtk_unittest_add_fixture clone +clone_fixture() { + setup() { + MOCK_GITREPO="$(pwd)/git" + } + + + teardown() { + rm -rf "${MOCK_GITREPO}" + } + + + shtk_unittest_add_test master_branch + master_branch_test() { + init_git_repo "${MOCK_GITREPO}" master other + shtk_git_clone "${MOCK_GITREPO}" master $(pwd)/a/b/c/clone + [ -f a/b/c/clone/file ] || fail "Files not checked out" + assert_file inline:"file in master\n" a/b/c/clone/file + } + + + shtk_unittest_add_test other_branch + other_branch_test() { + init_git_repo "${MOCK_GITREPO}" master other + shtk_git_clone "${MOCK_GITREPO}" other $(pwd)/a/b/c/clone + [ -f a/b/c/clone/file ] || fail "Files not checked out" + assert_file inline:"file in other\n" a/b/c/clone/file + } + + + shtk_unittest_add_test already_exists + already_exists_test() { + mkdir -p usr/src + assert_command -s exit:1 \ + -e match:"Cannot clone into $(pwd)/usr/src.*exists" \ + shtk_git_clone "${MOCK_GITREPO}" master "$(pwd)/usr/src" + } + + + shtk_unittest_add_test permission_denied + permission_denied_test() { + [ "$(id -u)" -ne 0 ] || skip "Cannot run test as root" + + init_git_repo "${MOCK_GITREPO}" master + mkdir usr + chmod 555 usr + assert_command -s exit:1 -e match:"could not create" \ + shtk_git_clone "${MOCK_GITREPO}" master "$(pwd)/usr/src" + } + + + shtk_unittest_add_test git_fails + git_fails_test() { + init_git_repo "${MOCK_GITREPO}" master + assert_command -s exit:1 -e match:"git clone failed" \ + shtk_git_clone "${MOCK_GITREPO}" non-existent "$(pwd)/usr/src" + } +} + + +shtk_unittest_add_fixture update +update_fixture() { + setup() { + MOCK_GITREPO="$(pwd)/git" + } + + + teardown() { + rm -rf "${MOCK_GITREPO}" + } + + + shtk_unittest_add_test ok + ok_test() { + init_git_repo "${MOCK_GITREPO}" master + + assert_command -o ignore -e ignore git clone "${MOCK_GITREPO}" tmp + + shtk_git_update master tmp + assert_file inline:"file in master\n" tmp/file + + echo "second revision" >tmp/file + assert_command -o ignore -e ignore -w tmp git commit -m iterate file + assert_command -o ignore -e ignore -w tmp git push + assert_command -o ignore -e ignore -w tmp git reset --hard HEAD^1 + + assert_file inline:"file in master\n" tmp/file + shtk_git_update master tmp + assert_file inline:"second revision\n" tmp/file + } + + + shtk_unittest_add_test does_not_exist + does_not_exist_test() { + assert_command -s exit:1 -e match:"Cannot update tmp; .*not exist" \ + shtk_git_update master tmp + } + + + shtk_unittest_add_test git_fails + git_fails_test() { + init_git_repo "${MOCK_GITREPO}" master + assert_command -o ignore -e ignore git clone "${MOCK_GITREPO}" tmp + assert_command -s exit:1 -e match:"git update failed" \ + shtk_git_update non-existent tmp + } +} diff --git a/man/shtk.3 b/man/shtk.3 index ae2ec0b..98bf901 100644 --- a/man/shtk.3 +++ b/man/shtk.3 @@ -25,7 +25,7 @@ .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE .\" OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -.Dd February 6, 2017 +.Dd January 6, 2025 .Dt SHTK 3 .Os .Sh NAME @@ -96,6 +96,7 @@ section below. .Xr shtk_config 3 , .Xr shtk_cvs 3 , .Xr shtk_fs 3 , +.Xr shtk_git 3 , .Xr shtk_hw 3 , .Xr shtk_list 3 , .Xr shtk_process 3 , diff --git a/man/shtk_git.3 b/man/shtk_git.3 new file mode 100644 index 0000000..3e582fd --- /dev/null +++ b/man/shtk_git.3 @@ -0,0 +1,48 @@ +.\" Copyright 2025 Julio Merino +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions are +.\" met: +.\" +.\" * Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" * Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +.\" "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +.\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +.\" A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +.\" OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +.\" LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +.\" OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +.Dd January 6, 2025 +.Dt SHTK_GIT 3 +.Os +.Sh NAME +.Nm git +.Nd Utilities to invoke Git and wrappers to simplify its operation +.Sh LIBRARY +shtk_import +.Nm +.Sh DESCRIPTION +The +.Nm +module provides utilities to invoke the Git utility and to simplify its +operation. +.Sh SEE ALSO +.Xr shtk 3 , +.Xr shtk_git_clone 3 , +.Xr shtk_git_fetch 3 , +.Xr shtk_git_update 3 +.Sh HISTORY +.Nm +first appeared in +.Nm shtk +1.8. diff --git a/man/shtk_git_clone.3 b/man/shtk_git_clone.3 new file mode 100644 index 0000000..82580f6 --- /dev/null +++ b/man/shtk_git_clone.3 @@ -0,0 +1,71 @@ +.\" Copyright 2025 Julio Merino +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions are +.\" met: +.\" +.\" * Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" * Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +.\" "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +.\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +.\" A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +.\" OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +.\" LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +.\" OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +.Dd January 6, 2025 +.Dt SHTK_GIT_CLONE 3 +.Os +.Sh NAME +.Nm shtk_git_clone +.Nd Checks out a new working copy out of a Git repository +.Sh LIBRARY +shtk_import git +.Sh SYNOPSIS +.Nm +.Ar repo +.Ar branch +.Ar directory +.Sh DESCRIPTION +The +.Nm +function checks out a new working copy of the repository +.Ar repo +into +.Ar directory +using the given +.Ar branch . +The +.Ar directory +must not exist. +.Pp +In general, you should resort to using the higher-level +.Xr shtk_git_fetch 3 +wrapper as it properly handles the case of already existing working +copies. +.Sh EXAMPLES +.Bd -literal -offset indent +shtk_git_clone https://example.com/repo.git master /usr/src +.Ed +.Sh ERRORS +.Nm +aborts execution with an error if the given +.Ar directory +already exists or if the Git clone operation fails. +.Sh SEE ALSO +.Xr shtk 3 , +.Xr shtk_git 3 +.Sh HISTORY +.Nm +first appeared in +.Nm shtk +1.8. diff --git a/man/shtk_git_fetch.3 b/man/shtk_git_fetch.3 new file mode 100644 index 0000000..3373da9 --- /dev/null +++ b/man/shtk_git_fetch.3 @@ -0,0 +1,75 @@ +.\" Copyright 2025 Julio Merino +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions are +.\" met: +.\" +.\" * Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" * Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +.\" "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +.\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +.\" A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +.\" OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +.\" LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +.\" OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +.Dd January 6, 2025 +.Dt SHTK_GIT_FETCH 3 +.Os +.Sh NAME +.Nm shtk_git_fetch +.Nd Checks out or updates a Git working copy +.Sh LIBRARY +shtk_import git +.Sh SYNOPSIS +.Nm +.Ar repo +.Ar branch +.Ar directory +.Sh DESCRIPTION +The +.Nm +function is a simple wrapper over the lower-level +.Xr shtk_git_checkout 3 +and +.Xr shtk_git_update 3 +functions, using one or the other depending on the status of the local +working copy. +.Pp +More specifically: if +.Ar directory +does not yet exist or it is empty, the +.Nm +function checks out a new working copy of the repository +.Ar repo +into it using the given +.Ar branch . +If +.Ar directory +does exist and contains a +.Pa Git +control directory, then the +.Nm +function performs a working copy update of the repository using the given +.Ar branch . +.Sh EXAMPLES +.Bd -literal -offset indent +shtk_git_fetch https://example.com/repo.git master /usr/src +.Ed +.Sh SEE ALSO +.Xr shtk 3 , +.Xr shtk_git 3 +.Sh HISTORY +.Nm +first appeared in +.Nm shtk +1.8. diff --git a/man/shtk_git_update.3 b/man/shtk_git_update.3 new file mode 100644 index 0000000..adc6778 --- /dev/null +++ b/man/shtk_git_update.3 @@ -0,0 +1,64 @@ +.\" Copyright 2025 Julio Merino +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions are +.\" met: +.\" +.\" * Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" * Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +.\" "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +.\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +.\" A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +.\" OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +.\" LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +.\" OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +.Dd January 6, 2025 +.Dt SHTK_GIT_UPDATE 3 +.Os +.Sh NAME +.Nm shtk_git_update +.Nd Updates an existing working copy of a Git repository +.Sh LIBRARY +shtk_import git +.Sh SYNOPSIS +.Nm +.Ar branch +.Ar directory +.Sh DESCRIPTION +The +.Nm +function updates the existing working copy in +.Ar directory +to +.Ar branch . +.Pp +In general, you should resort to using the higher-level +.Xr shtk_git_fetch 3 +wrapper as it properly handles the case of missing working copies. +.Sh EXAMPLES +.Bd -literal -offset indent +shtk_git_update master /usr/src +.Ed +.Sh ERRORS +.Nm +aborts execution with an error if the given +.Ar directory +does not yet exist or if the Git update operation fails. +.Sh SEE ALSO +.Xr shtk 3 , +.Xr shtk_git 3 +.Sh HISTORY +.Nm +first appeared in +.Nm shtk +1.8.