Skip to content
This repository has been archived by the owner on Sep 6, 2022. It is now read-only.

Commit

Permalink
Merge pull request #663 from fastlane/483
Browse files Browse the repository at this point in the history
During Unsetting of auth clear the credential helper
  • Loading branch information
taquitos committed Apr 13, 2018
2 parents def085f + c8490a2 commit 48d48ad
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Added by fastlane.ci team
.keys
.ruby-version
!/spec/fixtures/files/.fastlane/ci/.keys
fastlane.log
fastlane.verbose.log
Expand Down
27 changes: 17 additions & 10 deletions app/shared/models/git_repo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class GitRepo

attr_accessor :temporary_storage_path

attr_reader :credential_scope

attr_reader :local_folder # where we are keeping the local repo checkout

attr_reader :notification_service # when we have issues, we need to push them somewhere
Expand Down Expand Up @@ -394,29 +396,34 @@ def setup_auth(repo_auth: self.repo_auth)
""
].join("\n")

scope = "local"
# we don't have a git repo yet, we have no choice and must use global
# TODO: check if we find a better way for the initial clone to work without setting system global state
@credential_scope = File.directory?(File.join(local_folder, ".git")) ? "local" : "global"

unless File.directory?(File.join(local_folder, ".git"))
# we don't have a git repo yet, we have no choice
# TODO: check if we find a better way for the initial clone to work without setting system global state
scope = "global"
end
use_credentials_command = <<~COMMAND
git config --#{scope} credential.helper 'store --file #{temporary_storage_path.shellescape}' #{local_folder}
COMMAND
# rubocop:disable Metrics/LineLength
use_credentials_command = "git config --#{credential_scope} credential.helper 'store --file #{temporary_storage_path.shellescape}' #{local_folder}"
# rubocop:enable Metrics/LineLength

# Uncomment if you want to debug git credential stuff, keeping it commented out because it's very noisey
# Uncomment next line if you want to debug git credential stuff, it's very noisey
# logger.debug("Setting credentials for #{git_config.git_url} with command: #{use_credentials_command}")
cmd = TTY::Command.new(printer: :quiet)
cmd.run(store_credentials_command, input: content)
cmd.run(use_credentials_command)
return temporary_storage_path
end

# any calls to this should be balanced with any calls to set_auth
def unset_auth
return unless temporary_storage_path.kind_of?(String)
# TODO: Also auto-clean those files from time to time, on server re-launch maybe, or background worker
FileUtils.rm(temporary_storage_path) if File.exist?(temporary_storage_path)

clear_credentials_command = "git config --#{credential_scope} --replace-all credential.helper \"\""

# Uncomment next line if you want to debug git credential stuff, it's very noisey
# logger.debug("Clearing credentials for #{git_config.git_url} with command: #{clear_credentials_command}")
cmd = TTY::Command.new(printer: :quiet)
cmd.run(clear_credentials_command)
end

def perform_block(use_global_git_mutex: true, &block)
Expand Down

0 comments on commit 48d48ad

Please sign in to comment.