Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
omnibus
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
GitLab
omnibus
Commits
ce20a434
Commit
ce20a434
authored
May 11, 2015
by
Steven Danna
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #477 from chef/ssd/move-directory-get-out-the-way
Forcibly remove a non-empty project dir before cloning
parents
9d387525
3635f816
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
0 deletions
+30
-0
lib/omnibus/fetchers/git_fetcher.rb
lib/omnibus/fetchers/git_fetcher.rb
+19
-0
spec/unit/fetchers/git_fetcher_spec.rb
spec/unit/fetchers/git_fetcher_spec.rb
+11
-0
No files found.
lib/omnibus/fetchers/git_fetcher.rb
View file @
ce20a434
...
@@ -64,6 +64,7 @@ module Omnibus
...
@@ -64,6 +64,7 @@ module Omnibus
if
cloned?
if
cloned?
git_fetch
(
resolved_version
)
unless
same_revision?
(
resolved_version
)
git_fetch
(
resolved_version
)
unless
same_revision?
(
resolved_version
)
else
else
force_recreate_project_dir!
unless
dir_empty?
(
project_dir
)
git_clone
git_clone
git_checkout
(
resolved_version
)
git_checkout
(
resolved_version
)
end
end
...
@@ -90,6 +91,24 @@ module Omnibus
...
@@ -90,6 +91,24 @@ module Omnibus
source
[
:git
]
source
[
:git
]
end
end
#
# Determine if a directory is empty
#
# @return [true, false]
#
def
dir_empty?
(
dir
)
Dir
.
entries
(
dir
).
reject
{
|
d
|
[
'.'
,
'..'
].
include?
(
d
)
}.
empty?
end
#
# Forcibly remove and recreate the project directory
#
def
force_recreate_project_dir!
log
.
warn
(
log_key
)
{
"Removing exisitng directory
#{
project_dir
}
before cloning"
}
FileUtils
.
rm_rf
(
project_dir
)
Dir
.
mkdir
(
project_dir
)
end
#
#
# Determine if the clone exists.
# Determine if the clone exists.
#
#
...
...
spec/unit/fetchers/git_fetcher_spec.rb
View file @
ce20a434
...
@@ -98,6 +98,7 @@ module Omnibus
...
@@ -98,6 +98,7 @@ module Omnibus
allow
(
subject
).
to
receive
(
:git_fetch
)
allow
(
subject
).
to
receive
(
:git_fetch
)
allow
(
subject
).
to
receive
(
:git_clone
)
allow
(
subject
).
to
receive
(
:git_clone
)
allow
(
subject
).
to
receive
(
:git_checkout
)
allow
(
subject
).
to
receive
(
:git_checkout
)
allow
(
subject
).
to
receive
(
:dir_empty?
).
and_return
(
true
)
allow
(
subject
).
to
receive
(
:resolved_version
).
and_return
(
"134aeba31234"
)
allow
(
subject
).
to
receive
(
:resolved_version
).
and_return
(
"134aeba31234"
)
end
end
...
@@ -126,6 +127,16 @@ module Omnibus
...
@@ -126,6 +127,16 @@ module Omnibus
context
'when the repository is not cloned'
do
context
'when the repository is not cloned'
do
before
{
allow
(
subject
).
to
receive
(
:cloned?
).
and_return
(
false
)
}
before
{
allow
(
subject
).
to
receive
(
:cloned?
).
and_return
(
false
)
}
context
"but a directory does exist"
do
before
{
expect
(
subject
).
to
receive
(
:dir_empty?
).
with
(
project_dir
).
and_return
(
false
)}
it
"forcefully removes and recreateds the directory"
do
expect
(
FileUtils
).
to
receive
(
:rm_rf
).
with
(
project_dir
).
and_return
(
project_dir
)
expect
(
Dir
).
to
receive
(
:mkdir
).
with
(
project_dir
).
and_return
(
0
)
subject
.
fetch
end
end
it
'clones the repository'
do
it
'clones the repository'
do
expect
(
subject
).
to
receive
(
:git_clone
).
once
expect
(
subject
).
to
receive
(
:git_clone
).
once
subject
.
fetch
subject
.
fetch
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment