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
b9a9e1cb
Commit
b9a9e1cb
authored
1 year ago
by
nfontrod
Browse files
Options
Downloads
Patches
Plain Diff
src/clone.rs: create a new clone subcommand
parent
02a678fe
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
+93
-0
93 additions, 0 deletions
src/clone.rs
with
93 additions
and
0 deletions
src/clone.rs
+
93
−
0
View file @
b9a9e1cb
// SPDX-FileCopyrightText: 2023 Nicolas Fontrodona
// SPDX-FileCopyrightText: 2023 Nicolas Fontrodona
//
//
// SPDX-License-Identifier: AGPL-3.0-or-later
// SPDX-License-Identifier: AGPL-3.0-or-later
use
std
::{
path
::
PathBuf
,
process
::{
exit
,
Command
},
};
use
colored
::
Colorize
;
use
crate
::{
init
,
pull
,
push
,
remote
};
/// 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
}
/// Check if the input remote dir
fn
check_remote_dir
(
url
:
&
PathBuf
,
adress
:
&
str
)
{
let
archives
=
pull
::
get_archive_list
(
&
url
,
&
adress
);
if
archives
.len
()
==
0
{
eprintln!
(
"{}: No archives found in {}!"
,
"error"
.red
(),
url
.to_str
()
.unwrap
()
.yellow
()
);
exit
(
1
);
}
}
/// Create a push the tar achive on the selected remote path
/// # Arguments
/// - `path`: The path used to clone .borg repository
/// - `hooks`: a bolean indicating whether or not to use hooks
/// - `compression`: The compression that will be used when creating an archive
/// - `mode`: The mode used for checkout
pub
fn
clone
(
path
:
&
str
,
hooks
:
bool
,
compression
:
&
str
,
mode
:
&
str
)
->
()
{
let
(
adress
,
url
)
=
push
::
split_path
(
path
);
let
borg_folder
=
get_borg_absolute_folder
();
if
borg_folder
.is_dir
()
{
eprintln!
(
"{}: {} already exits."
,
"error"
.red
(),
&
borg_folder
.display
()
);
exit
(
1
);
}
check_remote_dir
(
&
url
,
&
adress
);
let
full_url
=
if
adress
!=
"file"
{
format!
(
"{}:{}"
,
&
adress
,
&
url
.display
())
}
else
{
url
.canonicalize
()
.unwrap
()
.to_str
()
.unwrap
()
.to_owned
()
};
init
::
init_and_hook
(
hooks
,
compression
,
mode
);
remote
::
update_config
(
"origin"
,
&
full_url
,
false
);
pull
::
pull_all_archives
(
"origin"
);
}
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