Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
git_borg_linker
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
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LBMC
Hub
git_borg_linker
Commits
667e17d0
Commit
667e17d0
authored
May 15, 2024
by
nfontrod
Browse files
Options
Downloads
Patches
Plain Diff
src/remote.rs: add a function to check remote paths
parent
be2a92ba
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/remote.rs
+38
-3
38 additions, 3 deletions
src/remote.rs
with
38 additions
and
3 deletions
src/remote.rs
+
38
−
3
View file @
667e17d0
...
@@ -138,11 +138,46 @@ pub fn show() -> () {
...
@@ -138,11 +138,46 @@ pub fn show() -> () {
display_remotes
(
dic_remote
);
display_remotes
(
dic_remote
);
}
}
/// Turn a remote URL into an absolute path if located in the current
/// filesystem
///
/// # Arguments
/// - `url`: The URL to canonicalize or not
fn
add_url
(
url
:
String
)
->
String
{
let
tmp
=
url
.split
(
":"
)
.collect
::
<
Vec
<&
str
>>
();
if
tmp
.len
()
==
1
{
let
path
=
PathBuf
::
from
(
&
url
);
if
!
path
.is_dir
()
{
eprintln!
(
"{}: The local path {} is not a directory !"
,
"error"
.red
(),
&
url
.yellow
());
exit
(
1
);
}
path
.canonicalize
()
.unwrap
()
.to_str
()
.unwrap
()
.to_string
()
}
else
if
tmp
.len
()
==
2
&&
tmp
.get
(
0
)
.unwrap
()
==
&
"file"
{
let
path
=
PathBuf
::
from
(
tmp
.get
(
1
)
.unwrap
());
if
!
path
.is_dir
()
{
eprintln!
(
"{}: The local path {} is not a directory !"
,
"error"
.red
(),
&
url
.yellow
());
exit
(
1
);
}
path
.canonicalize
()
.unwrap
()
.to_str
()
.unwrap
()
.to_string
()
}
else
if
tmp
.len
()
==
2
{
let
tmp_url
=
tmp
.get
(
1
)
.unwrap
();
if
!
tmp_url
.starts_with
(
"/"
)
{
eprintln!
(
"{}: The remote path {} must be absolute !"
,
"error"
.red
(),
&
url
.yellow
());
exit
(
1
);
}
url
}
else
{
eprintln!
(
"{}: The path {} is not well defined !"
,
"error"
.red
(),
&
url
.yellow
());
exit
(
1
);
}
}
/// Function that update the current gblk config file for the project folder
/// Function that update the current gblk config file for the project folder
/// # Arguments
/// # Arguments
/// - `key` : The remote name to update
/// - `key` : The remote name to update
/// - `value`: The value of the key to update
/// - `value`: The value of the key to update
/// - `global: A bolean indicating whether to update the global or the local configuration
/// - `global
`
: A bolean indicating whether to update the global or the local configuration
pub
(
crate
)
fn
update_config
(
key
:
&
str
,
value
:
&
str
,
global
:
bool
)
->
()
{
pub
(
crate
)
fn
update_config
(
key
:
&
str
,
value
:
&
str
,
global
:
bool
)
->
()
{
let
mut
my_config
=
parse_config
(
global
);
let
mut
my_config
=
parse_config
(
global
);
let
mut
remotes
=
match
my_config
.gblk_remote
{
let
mut
remotes
=
match
my_config
.gblk_remote
{
...
@@ -152,14 +187,14 @@ pub(crate) fn update_config(key: &str, value: &str, global: bool) -> () {
...
@@ -152,14 +187,14 @@ pub(crate) fn update_config(key: &str, value: &str, global: bool) -> () {
let
mut
updated
=
false
;
let
mut
updated
=
false
;
for
r
in
remotes
.iter_mut
()
{
for
r
in
remotes
.iter_mut
()
{
if
r
.name
==
key
{
if
r
.name
==
key
{
r
.url
=
value
.to_owned
();
r
.url
=
add_url
(
value
.to_owned
()
)
;
updated
=
true
;
updated
=
true
;
}
}
}
}
if
!
updated
{
if
!
updated
{
remotes
.push
(
RemoteConfig
{
remotes
.push
(
RemoteConfig
{
name
:
key
.to_owned
(),
name
:
key
.to_owned
(),
url
:
value
.to_owned
(),
url
:
add_url
(
value
.to_owned
()
)
,
})
})
}
}
my_config
.gblk_remote
=
Some
(
remotes
);
my_config
.gblk_remote
=
Some
(
remotes
);
...
...
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