FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
gitkit/src/git.rs at docs/initial-docs · UniverLab/gitkit · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
UniverLab
/
gitkit
Public
Uh oh!
There was an error while loading.
Please reload this page
.
Notifications
You must be signed in to change notification settings
Fork
1
Star
3
Code
Issues
0
Pull requests
0
Discussions
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
gitkit
/
src
/
git.rs
Copy path
More file actions
More file actions
Latest commit
History
History
History
35 lines (29 loc) · 819 Bytes
Breadcrumbs
gitkit
/
src
/
git.rs
Copy path
File metadata and controls
35 lines (29 loc) · 819 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use
anyhow
::
Result
;
use
std
::
path
::
Path
;
use
std
::
process
::
Command
;
/// Check if directory is a valid git repository.
pub
fn
is_git_repo
(
)
->
bool
{
Command
::
new
(
"git"
)
.
args
(
[
"rev-parse"
,
"--is-inside-work-tree"
]
)
.
output
(
)
.
map
(
|o| o
.
status
.
success
(
)
)
.
unwrap_or
(
false
)
}
/// Check if .git directory exists.
fn
git_dir_exists
(
)
->
bool
{
Path
::
new
(
".git"
)
.
exists
(
)
}
/// Initialize git repository if not already a git repo.
pub
fn
init_if_needed
(
)
->
Result
<
bool
>
{
if
git_dir_exists
(
)
{
return
Ok
(
false
)
;
}
Command
::
new
(
"git"
)
.
arg
(
"init"
)
.
output
(
)
.
map_err
(
|e| anyhow
::
anyhow!
(
"Failed to run 'git init': {}"
,
e
)
)
?
;
if
!
is_git_repo
(
)
{
anyhow
::
bail!
(
"git init succeeded but .git not found"
)
;
}
Ok
(
true
)
}
Back
|
FazBrowse Home
|
New Git URL