Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
Development_Environment
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Montaño Sarria, Andres Felipe
Development_Environment
Commits
4ef4fbaa
Commit
4ef4fbaa
authored
3 months ago
by
Montaño Sarria, Andres Felipe
Browse files
Options
Downloads
Patches
Plain Diff
Fix script now uses find properly
parent
9b18f5fa
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
scripts/set_dotdev_remotes.sh
+35
-9
35 additions, 9 deletions
scripts/set_dotdev_remotes.sh
with
35 additions
and
9 deletions
scripts/set_dotdev_remotes.
ba
sh
→
scripts/set_dotdev_remotes.sh
100644 → 100755
+
35
−
9
View file @
4ef4fbaa
#!/usr/bin/env bash
#!/usr/bin/env bash
#
#
# Updates Git remote URLs by replacing 'tecnalia.com' with 'tecnalia.dev'
# Updates Git remote URLs by replacing 'tecnalia.com' with 'tecnalia.dev'
# in all Git repositories under the current directory
#
recursively
in all Git repositories under the current directory
#
#
set
-e
uo
pipefail
#
Makes the script safer
set
-e
pipefail
#
Keep error handling but remove -u flag
# Color definitions for better readability
# Color definitions for better readability
readonly
GREEN
=
'\033[0;32m'
readonly
GREEN
=
'\033[0;32m'
readonly
YELLOW
=
'\033[1;33m'
readonly
YELLOW
=
'\033[1;33m'
readonly
BLUE
=
'\033[0;34m'
readonly
NC
=
'\033[0m'
# No Color
readonly
NC
=
'\033[0m'
# No Color
usage
()
{
usage
()
{
echo
"Usage:
$(
basename
"
$0
"
)
[-d|--dry-run]"
echo
"Usage:
$(
basename
"
$0
"
)
[-d|--dry-run] [-m|--max-depth N]"
echo
" -d, --dry-run Show changes without applying them"
echo
"Options:"
echo
" -d, --dry-run Show changes without applying them"
echo
" -m, --max-depth N Maximum depth for recursive search (default: unlimited)"
echo
" Use 1 for current directory only"
echo
" -h, --help Show this help message"
exit
1
exit
1
}
}
# Improved argument processing
# Improved argument processing
dry_run
=
0
dry_run
=
0
max_depth
=
""
while
[[
$#
-gt
0
]]
;
do
while
[[
$#
-gt
0
]]
;
do
case
$1
in
case
$1
in
-d
|
--dry-run
)
-d
|
--dry-run
)
dry_run
=
1
dry_run
=
1
shift
shift
;;
;;
-m
|
--max-depth
)
if
[[
-n
"
${
2
:-}
"
&&
$2
=
~ ^[0-9]+
$
]]
;
then
max_depth
=
"-maxdepth
$2
"
shift
2
else
echo
"Error: --max-depth requires a number"
usage
fi
;;
-h
|
--help
)
-h
|
--help
)
usage
usage
;;
;;
...
@@ -40,7 +56,11 @@ process_repo() {
...
@@ -40,7 +56,11 @@ process_repo() {
local
repo_path
=
$1
local
repo_path
=
$1
local
remote
=
$2
local
remote
=
$2
local
remote_url
local
remote_url
remote_url
=
$(
git
-C
"
${
repo_path
}
"
remote get-url
"
${
remote
}
"
)
if
!
remote_url
=
$(
git
-C
"
${
repo_path
}
"
remote get-url
"
${
remote
}
"
2>/dev/null
)
;
then
echo
" Warning: Could not get URL for remote
${
remote
}
"
>
&2
return
1
fi
if
[[
${
remote_url
}
==
*
"tecnalia.com"
*
]]
;
then
if
[[
${
remote_url
}
==
*
"tecnalia.com"
*
]]
;
then
local
new_url
=
${
remote_url
//tecnalia.com/tecnalia.dev
}
local
new_url
=
${
remote_url
//tecnalia.com/tecnalia.dev
}
...
@@ -64,24 +84,30 @@ process_repo() {
...
@@ -64,24 +84,30 @@ process_repo() {
main
()
{
main
()
{
local
count
=
0
local
count
=
0
local
errors
=
0
local
errors
=
0
local
repos_found
=
0
echo
-e
"
${
BLUE
}
Starting recursive search for Git repositories...
${
NC
}
"
# Use process substitution for better handling of spaces in names
# Use process substitution for better handling of spaces in names
while
IFS
=
read
-r
-d
''
git_folder
;
do
while
IFS
=
read
-r
-d
''
git_folder
||
[
-n
"
$git_folder
"
]
;
do
((
repos_found++
))
repo_path
=
$(
dirname
"
$(
readlink
-f
"
${
git_folder
}
"
)
"
)
repo_path
=
$(
dirname
"
$(
readlink
-f
"
${
git_folder
}
"
)
"
)
echo
-e
"
${
BLUE
}
Processing repository:
${
repo_path
}${
NC
}
"
while
IFS
=
read
-r
remote
;
do
while
IFS
=
read
-r
remote
||
[
-n
"
$remote
"
]
;
do
if
process_repo
"
${
repo_path
}
"
"
${
remote
}
"
;
then
if
process_repo
"
${
repo_path
}
"
"
${
remote
}
"
;
then
((
count++
))
((
count++
))
else
else
((
errors++
))
((
errors++
))
fi
fi
done
< <
(
git
-C
"
${
repo_path
}
"
remote
)
done
< <
(
git
-C
"
${
repo_path
}
"
remote
2>/dev/null
||
echo
""
)
done
< <
(
find
.
-name
'.git'
-type
d
-print0
)
done
< <
(
find
.
${
max_depth
:-}
-name
'.git'
-type
d
-print0
2>/dev/null
||
echo
""
)
# Final summary
# Final summary
echo
echo
echo
"Execution summary:"
echo
"Execution summary:"
echo
" Git repositories found:
$repos_found
"
echo
" Repositories processed:
$count
"
echo
" Repositories processed:
$count
"
[[
$errors
-gt
0
]]
&&
echo
" Errors found:
$errors
"
[[
$errors
-gt
0
]]
&&
echo
" Errors found:
$errors
"
[[
$dry_run
-eq
1
]]
&&
echo
" (Dry-run mode: no changes were made)"
[[
$dry_run
-eq
1
]]
&&
echo
" (Dry-run mode: no changes were made)"
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment