Skip to content

Commit

Permalink
[match] Always checkout the specified branch as master may not be the…
Browse files Browse the repository at this point in the history
… default branch (#16622)

* Always checkout the specified branch as master may not be the default branch.

* Remember to press enter to actually run rubocop
  • Loading branch information
mbogh committed Jul 7, 2020
1 parent f18ef00 commit 2ad0aaa
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 25 deletions.
2 changes: 1 addition & 1 deletion match/lib/match/storage/git_storage.rb
Expand Up @@ -113,7 +113,7 @@ def download
UI.user_error!("Error cloning repo, make sure you have access to it '#{self.git_url}'")
end

checkout_branch unless self.branch == "master"
checkout_branch
end

def human_readable_description
Expand Down
60 changes: 36 additions & 24 deletions match/spec/storage/git_storage_spec.rb
Expand Up @@ -16,18 +16,22 @@
path = Dir.mktmpdir # to have access to the actual path
expect(Dir).to receive(:mktmpdir).and_return(path)
git_url = "https://github.com/fastlane/fastlane/tree/master/certificates"
git_branch = "master"
shallow_clone = true
command = "git clone #{git_url.shellescape} #{path.shellescape} --depth 1 --no-single-branch"
to_params = {
command: command,
print_all: nil,
print_command: nil
}

expect(FastlaneCore::CommandExecutor).
to receive(:execute).
with(to_params).
and_return(nil)

expected_commands = [
"git clone #{git_url.shellescape} #{path.shellescape} --depth 1 --no-single-branch",
"git --no-pager branch --list origin/#{git_branch} --no-color -r",
"git checkout --orphan #{git_branch}",
"git reset --hard"
]
expected_commands.each do |command|
expect(FastlaneCore::CommandExecutor).to receive(:execute).once.with({
command: command,
print_all: nil,
print_command: nil
}).and_return("")
end

storage = Match::Storage::GitStorage.new(
git_url: git_url,
Expand All @@ -43,18 +47,22 @@
path = Dir.mktmpdir # to have access to the actual path
expect(Dir).to receive(:mktmpdir).and_return(path)
git_url = "https://github.com/fastlane/fastlane/tree/master/certificates"
git_branch = "master"
shallow_clone = false
command = "git clone #{git_url.shellescape} #{path.shellescape}"
to_params = {
command: command,
print_all: nil,
print_command: nil
}

expect(FastlaneCore::CommandExecutor).
to receive(:execute).
with(to_params).
and_return(nil)

expected_commands = [
"git clone #{git_url.shellescape} #{path.shellescape}",
"git --no-pager branch --list origin/#{git_branch} --no-color -r",
"git checkout --orphan #{git_branch}",
"git reset --hard"
]
expected_commands.each do |command|
expect(FastlaneCore::CommandExecutor).to receive(:execute).once.with({
command: command,
print_all: nil,
print_command: nil
}).and_return("")
end

storage = Match::Storage::GitStorage.new(
git_url: git_url,
Expand Down Expand Up @@ -104,6 +112,7 @@
path = Dir.mktmpdir # to have access to the actual path
expect(Dir).to receive(:mktmpdir).and_return(path)
git_url = "https://github.com/fastlane/fastlane/tree/master/certificates"
git_branch = "master"
random_file = "random_file"

storage = Match::Storage::GitStorage.new(
Expand All @@ -115,11 +124,14 @@
)

expected_commands = [
"git clone #{git_url.shellescape} #{path.shellescape}",
"git --no-pager branch --list origin/#{git_branch} --no-color -r",
"git checkout --orphan #{git_branch}",
"git reset --hard",
"git add #{random_file}",
"git add match_version.txt",
"git commit -m " + '[fastlane] Updated appstore and platform ios'.shellescape,
"git push origin master",
"git clone #{git_url.shellescape} #{path.shellescape}"
"git push origin #{git_branch}"
]

expected_commands.each do |command|
Expand Down

0 comments on commit 2ad0aaa

Please sign in to comment.