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
b27ea5af
Commit
b27ea5af
authored
Jun 29, 2022
by
nfontrod
Browse files
Options
Downloads
Patches
Plain Diff
src/create_hooks.rs: add a delete hooks option and create 2 new aliases
parent
ba3eaec3
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/create_hooks.rs
+39
-7
39 additions, 7 deletions
src/create_hooks.rs
with
39 additions
and
7 deletions
src/create_hooks.rs
+
39
−
7
View file @
b27ea5af
use
std
::
fs
;
use
std
::
fs
::
File
;
use
std
::
fs
::
File
;
use
std
::
fs
::
OpenOptions
;
use
std
::
fs
::
OpenOptions
;
use
std
::
io
::
Write
;
use
std
::
io
::
Write
;
...
@@ -93,18 +94,27 @@ fn update_config_file() {
...
@@ -93,18 +94,27 @@ fn update_config_file() {
eprintln!
(
"Error: The file .git/config wasn't found"
);
eprintln!
(
"Error: The file .git/config wasn't found"
);
exit
(
19
);
exit
(
19
);
}
}
let
content
=
fs
::
read_to_string
(
&
git_config
)
.unwrap
();
let
alias
=
format!
(
"{}
\n\t
{}
\n\t
{}"
,
"co = checkout -q"
,
"conh = -c core.hooksPath=/dev/null checkout"
,
"cnh = -c core.hooksPath=/dev/null commit"
);
if
!
content
.contains
(
&
alias
)
{
let
mut
file
=
OpenOptions
::
new
()
let
mut
file
=
OpenOptions
::
new
()
.write
(
true
)
.write
(
true
)
.append
(
true
)
.append
(
true
)
.open
(
&
git_config
)
.open
(
&
git_config
)
.unwrap
();
.unwrap
();
writeln!
(
file
,
"[alias]
\n\t
co = checkout -q"
)
.unwrap
();
writeln!
(
file
,
"[alias]
\n\t
{}"
,
alias
)
.unwrap
();
}
}
}
/// Create 2 files in `.git/hooks` folder
/// Create 2 files in `.git/hooks` folder
///
///
/// 1. Create post-commit hook
/// 1. Create post-commit hook
///
3
. Create post-checkout hook
///
2
. Create post-checkout hook
///
///
/// # Arguments
/// # Arguments
/// * `compression`: The compression that will automatically be used to save the results folder (no, lz4, zstd, zlib or lzma) after a git commit
/// * `compression`: The compression that will automatically be used to save the results folder (no, lz4, zstd, zlib or lzma) after a git commit
...
@@ -138,3 +148,25 @@ pub fn create_hooks(compression: &str, mode: &str) {
...
@@ -138,3 +148,25 @@ pub fn create_hooks(compression: &str, mode: &str) {
create_file
(
&
git_folder
,
fname
,
&
content
);
create_file
(
&
git_folder
,
fname
,
&
content
);
}
}
}
}
/// Delete 2 hooks files in `.git/hooks` folder
///
/// 1. Create post-commit hook
/// 2. Create post-checkout hook
pub
fn
delete_hooks
()
{
let
git_folder
=
get_hooks_folder
();
let
file_name
=
vec!
[
"post-commit"
,
"post-checkout"
];
for
cfile
in
file_name
{
let
mut
hfile
=
git_folder
.to_owned
();
hfile
.push
(
cfile
);
let
cmd
=
format!
(
"rm {}"
,
hfile
.to_str
()
.unwrap
());
let
output
=
Command
::
new
(
"sh"
)
.arg
(
"-c"
)
.arg
(
cmd
)
.output
()
.unwrap
();
match
output
.status
.code
()
.unwrap
()
{
0
=>
(),
num
=>
{
eprintln!
(
"{}"
,
String
::
from_utf8
(
output
.stderr
)
.unwrap
());
exit
(
num
)
}
}
}
}
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