Skip to content
Snippets Groups Projects
Commit dd1de371 authored by Montaño Sarria, Andres Felipe's avatar Montaño Sarria, Andres Felipe
Browse files

Add script to replace tecnalia.com by tecnalia.dev at git repos

parent 61c3d491
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env bash
#
# Updates Git remote URLs by replacing 'tecnalia.com' with 'tecnalia.dev'
# in all Git repositories under the current directory
#
set -euo pipefail # Makes the script safer
# Color definitions for better readability
readonly GREEN='\033[0;32m'
readonly YELLOW='\033[1;33m'
readonly NC='\033[0m' # No Color
usage() {
echo "Usage: $(basename "$0") [-d|--dry-run]"
echo " -d, --dry-run Show changes without applying them"
exit 1
}
# Improved argument processing
dry_run=0
while [[ $# -gt 0 ]]; do
case $1 in
-d|--dry-run)
dry_run=1
shift
;;
-h|--help)
usage
;;
*)
echo "Error: Unknown option $1"
usage
;;
esac
done
# Function to process a repository
process_repo() {
local repo_path=$1
local remote=$2
local remote_url
remote_url=$(git -C "${repo_path}" remote get-url "${remote}")
if [[ ${remote_url} == *"tecnalia.com"* ]]; then
local new_url=${remote_url//tecnalia.com/tecnalia.dev}
echo -e "${YELLOW}Found deprecated remote URL${NC}"
echo " Repository: ${repo_path}"
echo " Remote: ${remote}"
echo " Current URL: ${remote_url}"
echo " New URL: ${new_url}"
if [[ ${dry_run} -eq 0 ]]; then
if git -C "${repo_path}" remote set-url "${remote}" "${new_url}"; then
echo -e " ${GREEN}Replacement completed!${NC}"
else
echo " Error updating remote URL" >&2
return 1
fi
fi
fi
}
main() {
local count=0
local errors=0
# Use process substitution for better handling of spaces in names
while IFS= read -r -d '' git_folder; do
repo_path=$(dirname "$(readlink -f "${git_folder}")")
while IFS= read -r remote; do
if process_repo "${repo_path}" "${remote}"; then
((count++))
else
((errors++))
fi
done < <(git -C "${repo_path}" remote)
done < <(find . -name '.git' -type d -print0)
# Final summary
echo
echo "Execution summary:"
echo " Repositories processed: $count"
[[ $errors -gt 0 ]] && echo " Errors found: $errors"
[[ $dry_run -eq 1 ]] && echo " (Dry-run mode: no changes were made)"
}
main
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment