Skip to content

Instantly share code, notes, and snippets.

@koraysels
Last active June 2, 2025 08:21
Show Gist options
  • Save koraysels/33c8d1706deaab7e54aa1342d8f51678 to your computer and use it in GitHub Desktop.
Save koraysels/33c8d1706deaab7e54aa1342d8f51678 to your computer and use it in GitHub Desktop.
IP1-repo-checkout-or-update
#!/bin/bash
# Target date and time in Brussels time
TARGET_DATE="2025-05-28T23:59:00+02:00"
# Read the file line by line
while IFS= read -r line; do
# Extract folder name and repo URL
folder_name=$(echo "$line" | awk '{print $1}')
repo_url=$(echo "$line" | awk '{print $2}')
if [ -d "$folder_name/.git" ]; then
echo "Updating existing repo in $folder_name"
cd "$folder_name"
git fetch --all
# Find the last commit before the target date
commit_hash=$(GIT_COMMITTER_DATE="$TARGET_DATE" git rev-list -1 --before="$TARGET_DATE" origin/main)
if [ -z "$commit_hash" ]; then
echo "No commit found before $TARGET_DATE"
else
echo "Resetting to commit $commit_hash"
git reset --hard "$commit_hash"
fi
cd ..
else
echo "Cloning $repo_url into $folder_name"
git clone "$repo_url" "$folder_name"
cd "$folder_name"
# Find the last commit before the target date
commit_hash=$(GIT_COMMITTER_DATE="$TARGET_DATE" git rev-list -1 --before="$TARGET_DATE" main)
if [ -z "$commit_hash" ]; then
echo "No commit found before $TARGET_DATE"
else
echo "Checking out commit $commit_hash"
git checkout "$commit_hash"
fi
cd ..
fi
done < repos.txt
2_Pentacode [email protected]:kdg-ti/integratieproject-1/202425/2_pentacode/development.git
3_Codestorm [email protected]:kdg-ti/integratieproject-1/202425/3_codestorm/development.git
10_MergeConflict [email protected]:kdg-ti/integratieproject-1/202425/10_merge-conflict/development.git
14_Team14 [email protected]:kdg-ti/integratieproject-1/202425/14_team-14/development.git
16_MEWTS [email protected]:kdg-ti/integratieproject-1/202425/16_mewts/development.git
17_Team17 [email protected]:kdg-ti/integratieproject-1/202425/17_team-17/development.git
19_YoJoPiLa [email protected]:kdg-ti/integratieproject-1/202425/19_yojopila/development.git
20_CtrlAltElite [email protected]:kdg-ti/integratieproject-1/202425/20_ctrl-alt-elite/development.git
21_CRMH-Solutions [email protected]:kdg-ti/integratieproject-1/202425/21_crmh-solutions/development.git
23_PanelPioniers [email protected]:kdg-ti/integratieproject-1/202425/23_panelpioniers/burgerberaad.git
24_Whimp24 [email protected]:kdg-ti/integratieproject-1/202425/24_whimp24/development.git
25_PanelPioneers [email protected]:kdg-ti/integratieproject-1/202425/25_panel-pioneers/panelproject.git
26_API-Avengers [email protected]:kdg-ti/integratieproject-1/202425/26_apivengers/development.git
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment