Skip to content

Instantly share code, notes, and snippets.

@jpmens
Created December 5, 2023 15:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpmens/3ed741405934841f78810ea72d6d08d7 to your computer and use it in GitHub Desktop.
Save jpmens/3ed741405934841f78810ea72d6d08d7 to your computer and use it in GitHub Desktop.
#!/bin/sh
# Copyright 2023 Codeberg e.V.
# This work is marked with CC0 1.0 Universal. To view a copy of this
# license, visit http://creativecommons.org/publicdomain/zero/1.0
# This work is dedicated to the public domains under the terms of the
# Unlicense, visit https://unlicense.org/
# You are free to choose either the CC0 1.0 Univesal or Unlicense for this
# work.
# via https://mastodon.social/@Codeberg@social.anoxinon.de/111524635192557943
repo="" # url to repository
dir="" # directory to cd into (or fail)
refspec="main"
cd $dir || exit 2
if [ -d repo.git ]; then
cd repo.git
OLD_HEAD=$(git rev-parse HEAD)
git pull -q origin $refspec
NEW_HEAD=$(git rev-parse HEAD)
else
git clone -q "$repo" repo.git
cd repo.git
OLD_HEAD=xxx
NEW_HEAD=$(git rev-parse HEAD)
fi
[ $OLD_HEAD = $NEW_HEAD ] && exit
# now perform whatever you want to do ...
echo "I am in $(pwd)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment