Last active
June 18, 2025 19:11
-
-
Save koraysels/33c8d1706deaab7e54aa1342d8f51678 to your computer and use it in GitHub Desktop.
IP1-repo-checkout-or-update
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Target date and time in Brussels time | |
| TARGET_DATE="2025-05-30T23:59:00+02:00" | |
| # Get the absolute path of the starting directory | |
| SCRIPT_DIR=$(pwd) | |
| echo "Script starting in directory: $SCRIPT_DIR" | |
| # Read the file line by line | |
| while IFS= read -r line; do | |
| echo "---" | |
| echo "Processing line: '$line'" | |
| # Skip completely empty lines | |
| if [ -z "$line" ]; then | |
| echo "Skipping empty line" | |
| continue | |
| fi | |
| # Extract folder name and repo URL, trim whitespace | |
| folder_name=$(echo "$line" | awk '{print $1}' | xargs) | |
| repo_url=$(echo "$line" | awk '{print $2}' | xargs) | |
| echo "Folder name: '$folder_name'" | |
| echo "Repo URL: '$repo_url'" | |
| # Skip if folder name is empty | |
| if [ -z "$folder_name" ]; then | |
| echo "Skipping line with no folder name" | |
| continue | |
| fi | |
| # Check if repo URL is empty or doesn't start with git@ | |
| if [ -z "$repo_url" ] || [[ ! "$repo_url" =~ ^git@ ]]; then | |
| empty_folder_name="${folder_name}_EMPTY" | |
| echo "Creating empty folder: $empty_folder_name in $SCRIPT_DIR" | |
| mkdir -p "$SCRIPT_DIR/$empty_folder_name" | |
| continue | |
| fi | |
| # Use subshells to avoid directory pollution | |
| if [ -d "$SCRIPT_DIR/$folder_name/.git" ]; then | |
| echo "Updating existing repo in $folder_name" | |
| ( | |
| cd "$SCRIPT_DIR/$folder_name" || exit 1 | |
| echo "Working in: $(pwd)" | |
| 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 | |
| ) | |
| else | |
| echo "Cloning $repo_url into $SCRIPT_DIR/$folder_name" | |
| ( | |
| cd "$SCRIPT_DIR" || exit 1 | |
| echo "Cloning from: $(pwd)" | |
| git clone "$repo_url" "$folder_name" | |
| if [ -d "$folder_name" ]; then | |
| cd "$folder_name" || exit 1 | |
| echo "Working in cloned repo: $(pwd)" | |
| # 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 | |
| else | |
| echo "Failed to clone $repo_url" | |
| fi | |
| ) | |
| fi | |
| echo "Main script still in: $(pwd)" | |
| done < repos.txt | |
| echo "Script finished in directory: $(pwd)" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 2_Pentacode git@gitlab.com:kdg-ti/integratieproject-1/202425/2_pentacode/development.git | |
| 3_Codestorm git@gitlab.com:kdg-ti/integratieproject-1/202425/3_codestorm/development.git | |
| 10_MergeConflict git@gitlab.com:kdg-ti/integratieproject-1/202425/10_merge-conflict/development.git | |
| 14_Team14 git@gitlab.com:kdg-ti/integratieproject-1/202425/14_team-14/development.git | |
| 16_MEWTS git@gitlab.com:kdg-ti/integratieproject-1/202425/16_mewts/development.git | |
| 17_Team17 git@gitlab.com:kdg-ti/integratieproject-1/202425/17_team-17/development.git | |
| 19_YoJoPiLa git@gitlab.com:kdg-ti/integratieproject-1/202425/19_yojopila/development.git | |
| 20_CtrlAltElite git@gitlab.com:kdg-ti/integratieproject-1/202425/20_ctrl-alt-elite/development.git | |
| 21_CRMH-Solutions git@gitlab.com:kdg-ti/integratieproject-1/202425/21_crmh-solutions/development.git | |
| 23_PanelPioniers git@gitlab.com:kdg-ti/integratieproject-1/202425/23_panelpioniers/burgerberaad.git | |
| 24_Whimp24 git@gitlab.com:kdg-ti/integratieproject-1/202425/24_whimp24/development.git | |
| 25_PanelPioneers git@gitlab.com:kdg-ti/integratieproject-1/202425/25_panel-pioneers/panelproject.git | |
| 26_API-Avengers git@gitlab.com:kdg-ti/integratieproject-1/202425/26_apivengers/development.git | |
| Ali_Alpay git@gitlab.com:jaar2/android.git | |
| Atteya_Alessio git@gitlab.com:alessio.atteya/android_project_2025_festivals_performances.git | |
| Azoukane_Wail | |
| Bogaerts_Emma git@gitlab.com:emmabogaerts/ui2-2025-android.git | |
| Bogaerts_Jonas git@gitlab.com:jonas.bogaerts/groeiproject_android.git | |
| Croymans_Yorbe git@gitlab.com:yorbe.croymans/groeiproject-android.git | |
| Cuyt_Mathias | |
| De_Prekel_Sander git@gitlab.com:sanderdeprekel/ui_app.git |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
now it skips blank lines and also when no repo name it crates a folder with EMPTY in the foldername