Skip to content
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/travis/vcs/git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def write_netrc
end

def delete_netrc?
!data.keep_netrc?
ENV['DELETE_NETRC'] == 'true' || !data.keep_netrc?
end

def delete_netrc
Expand Down
17 changes: 16 additions & 1 deletion lib/travis/vcs/git/netrc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,22 @@ def apply
end

def delete
sh.raw "rm -f ${TRAVIS_HOME}/#{netrc_filename}"
host = Shellwords.escape(data.source_host)
file_path = "${TRAVIS_HOME}/#{netrc_filename}"

if netrc_filename == '_netrc'
# Windows
sh.raw %(
powershell -Command "
(Get-Content #{file_path}) |
Where-Object { $_ -notmatch 'login|password' } |
Set-Content #{file_path}
"
)
else
# Linux/macOS
sh.raw "sed -i '/^machine #{host}/,/^$/ { /login/d; /password/d; }' #{file_path}"
end
end

private
Expand Down
8 changes: 6 additions & 2 deletions spec/build/git_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,12 @@
context "when keep_netrc is false" do
before { payload[:keep_netrc] = false }

it 'deletes .netrc' do
should include_sexp [:raw, "rm -f ${TRAVIS_HOME}/.netrc", assert: true]
it 'removes credentials from .netrc' do
should include_sexp(
:raw,
%r{^sed -i '/\^machine github\\.com/,/\^\$/ { /login/d; /password/d; }' \$\{TRAVIS_HOME\}/\.netrc$},
assert: true
)
end
end
end
Expand Down