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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LBMC
Hub
git_borg_linker
Commits
72965662
Verified
Commit
72965662
authored
2 years ago
by
nfontrod
Browse files
Options
Downloads
Patches
Plain Diff
src/clone.rs: major fixes in clone function
parent
592156bd
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
src/clone.rs
+54
-8
54 additions, 8 deletions
src/clone.rs
with
54 additions
and
8 deletions
src/clone.rs
+
54
−
8
View file @
72965662
use
std
::
path
::
PathBuf
;
use
std
::
path
::
PathBuf
;
use
std
::
process
::
exit
;
use
std
::
process
::
exit
;
use
std
::
process
::
Command
;
use
colored
::
Colorize
;
use
colored
::
Colorize
;
...
@@ -36,6 +37,49 @@ fn check_remote_dir(url: &PathBuf, adress: &str) {
...
@@ -36,6 +37,49 @@ fn check_remote_dir(url: &PathBuf, adress: &str) {
}
}
}
}
/// Function used to get borg repository folder only if
/// the project is inside a git repository and a results folder exits
/// # Return
/// Absolute path to borg repository
pub
fn
get_borg_absolute_folder
()
->
PathBuf
{
let
output
=
Command
::
new
(
"git"
)
.arg
(
"rev-parse"
)
.arg
(
"--show-cdup"
)
.output
()
.unwrap
();
match
output
.status
.code
()
.unwrap
()
{
128
=>
{
eprintln!
(
"Not a git repository !"
);
exit
(
128
);
}
127
=>
{
eprintln!
(
"Git not found !"
);
exit
(
127
);
}
0
=>
(),
num
=>
{
eprintln!
(
"{}"
,
String
::
from_utf8
(
output
.stderr
)
.unwrap
());
exit
(
num
)
}
}
let
mut
string_path
=
String
::
from_utf8
(
output
.stdout
)
.unwrap
();
if
string_path
.ends_with
(
'\n'
)
{
string_path
.pop
();
}
if
string_path
.is_empty
()
{
string_path
.push_str
(
"./"
);
}
let
mut
p
=
PathBuf
::
from
(
&
string_path
)
.canonicalize
()
.unwrap
();
let
mut
results
=
p
.clone
();
p
.push
(
".borg"
);
results
.push
(
"results"
);
if
!
results
.is_dir
()
{
eprintln!
(
"{} not found !"
,
results
.to_str
()
.unwrap
());
exit
(
1
);
}
p
}
/// Create a push the tar achive on the selected remote path
/// Create a push the tar achive on the selected remote path
/// # Arguments
/// # Arguments
/// - `remote`: The name of a remote
/// - `remote`: The name of a remote
...
@@ -44,25 +88,27 @@ fn check_remote_dir(url: &PathBuf, adress: &str) {
...
@@ -44,25 +88,27 @@ fn check_remote_dir(url: &PathBuf, adress: &str) {
/// - `mode`: The mode used for checkout
/// - `mode`: The mode used for checkout
pub
fn
clone
(
path
:
&
str
,
hooks
:
bool
,
compression
:
&
str
,
mode
:
&
str
)
->
()
{
pub
fn
clone
(
path
:
&
str
,
hooks
:
bool
,
compression
:
&
str
,
mode
:
&
str
)
->
()
{
let
(
adress
,
url
)
=
push
::
split_path
(
path
);
let
(
adress
,
url
)
=
push
::
split_path
(
path
);
let
(
borg_path
,
_
)
=
init
::
get_borg_folder
();
let
borg_folder
=
get_borg_absolute_folder
();
if
borg_path
.is_dir
()
{
if
borg_folder
.is_dir
()
{
eprintln!
(
"{}: {} already exits."
,
"error"
.red
(),
&
borg_path
.display
());
eprintln!
(
"{}: {} already exits."
,
"error"
.red
(),
&
borg_folder
.display
()
);
exit
(
1
);
exit
(
1
);
}
}
let
borg_folder
=
borg_path
.canonicalize
()
.unwrap
();
check_remote_dir
(
&
url
,
&
adress
);
check_remote_dir
(
&
url
,
&
adress
);
push
::
copy_file
(
&
borg_folder
,
&
url
,
&
adress
,
"
pull
"
);
push
::
copy_file
(
&
borg_folder
,
&
url
,
&
adress
,
"
clone
"
);
let
name
=
url
.file_name
()
.unwrap
()
.to_str
()
.unwrap
();
let
name
=
url
.file_name
()
.unwrap
()
.to_str
()
.unwrap
();
configt
::
create_named_local_config
(
name
);
configt
::
create_named_local_config
(
name
);
let
pf
=
url
.parent
()
.unwrap
()
.to_path_buf
();
let
pf
=
url
.parent
()
.unwrap
()
.to_path_buf
();
let
full_url
=
if
adress
!=
"file"
{
let
full_url
=
if
adress
!=
"file"
{
format!
(
"{}:{}"
,
&
adress
,
&
pf
.display
())
format!
(
"{}:{}"
,
&
adress
,
&
pf
.display
())
}
else
{
}
else
{
url
.to_str
()
.unwrap
()
.to_owned
()
pf
.to_str
()
.unwrap
()
.to_owned
()
};
};
remote
::
update_config
(
"origin"
,
&
full_url
,
false
);
remote
::
update_config
(
"origin"
,
&
full_url
,
false
);
let
gitignore
=
init
::
get_gitignore_file
();
init
::
update_gitignores
();
init
::
update_gitignore
(
&
gitignore
);
if
hooks
{
if
hooks
{
create_hooks
::
create_hooks
(
compression
,
mode
);
create_hooks
::
create_hooks
(
compression
,
mode
);
}
}
...
...
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