Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • main
1 result

Target

Select target project
  • andres.montano/development_environment
1 result
Select Git revision
  • main
1 result
Show changes
#!/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