Skip to content

Commit

Permalink
Merge pull request #1358 from mfilipe/git-progress-output
Browse files Browse the repository at this point in the history
Make --quiet flag dynamic in git commands
  • Loading branch information
casperisfine authored Aug 19, 2024
2 parents a6f1948 + 481c9d6 commit 516558d
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ GEM
multi_xml (0.6.0)
multipart-post (2.3.0)
mutex_m (0.2.0)
mysql2 (0.5.3)
mysql2 (0.5.6)
net-imap (0.4.12)
date
net-protocol
Expand Down
7 changes: 7 additions & 0 deletions docs/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,13 @@ production:
update_latest_deployed_ref: true
```

**`git_progress_output`** enables git commands verbosity in the deploys.

```yml
production:
git_progress_output: true
```

### Using Multiple Github Applications

A Github application can only authenticate to the Github organization it's installed in. If you want to deploy code from multiple Github organizations the `github` section of your `config/secrets.yml` will need to be formatted differently. The top-level keys should be the name of each Github organization, and the following sub-keys are the Github app details for that particular organization.
Expand Down
4 changes: 4 additions & 0 deletions lib/shipit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ def update_latest_deployed_ref
secrets.update_latest_deployed_ref
end

def git_progress_output
secrets.git_progress_output || false
end

def enforce_publish_config
secrets.enforce_publish_config.presence
end
Expand Down
14 changes: 9 additions & 5 deletions lib/shipit/stack_commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def env
def fetch_commit(commit)
create_directories
if valid_git_repository?(@stack.git_path)
git('fetch', 'origin', '--quiet', '--tags', '--force', commit.sha, env: env, chdir: @stack.git_path)
git('fetch', 'origin', *quiet_git_arg, '--tags', '--force', commit.sha, env: env, chdir: @stack.git_path)
else
@stack.clear_git_cache!
git_clone(@stack.repo_git_url, @stack.git_path, branch: @stack.branch, env: env, chdir: @stack.deploys_path)
Expand All @@ -26,7 +26,7 @@ def fetch_commit(commit)
def fetch
create_directories
if valid_git_repository?(@stack.git_path)
git('fetch', 'origin', '--quiet', '--tags', '--force', @stack.branch, env: env, chdir: @stack.git_path)
git('fetch', 'origin', *quiet_git_arg, '--tags', '--force', @stack.branch, env: env, chdir: @stack.git_path)
else
@stack.clear_git_cache!
git_clone(@stack.repo_git_url, @stack.git_path, branch: @stack.branch, env: env, chdir: @stack.deploys_path)
Expand All @@ -35,7 +35,7 @@ def fetch

def fetched?(commit)
if valid_git_repository?(@stack.git_path)
git('rev-parse', '--quiet', '--verify', "#{commit.sha}^{commit}", env: env, chdir: @stack.git_path)
git('rev-parse', *quiet_git_arg, '--verify', "#{commit.sha}^{commit}", env: env, chdir: @stack.git_path)
else
# When the stack's git cache is not valid, the commit is
# NOT fetched. To keep the interface of this method
Expand Down Expand Up @@ -88,7 +88,7 @@ def with_temporary_working_directory(commit: nil, recursive: true)
'-c',
'advice.detachedHead=false',
'checkout',
'--quiet',
*quiet_git_arg,
commit.sha,
chdir: git_dir
).run! if commit
Expand All @@ -109,7 +109,7 @@ def git_cmd_succeeds?(path)
end

def git_clone(url, path, branch: 'main', **kwargs)
git('clone', '--quiet', *modern_git_args, '--recursive', '--branch', branch, url, path, **kwargs)
git('clone', *quiet_git_arg, *modern_git_args, '--recursive', '--branch', branch, url, path, **kwargs)
end

def modern_git_args
Expand All @@ -121,6 +121,10 @@ def create_directories
FileUtils.mkdir_p(@stack.deploys_path)
end

def quiet_git_arg
Shipit.git_progress_output ? [] : ['--quiet']
end

private

def github
Expand Down
9 changes: 9 additions & 0 deletions test/unit/deploy_commands_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,15 @@ def setup
assert_equal expected, command.args.map(&:to_s)
end

test "#fetch does not use --quit if git_progress_output is enabled" do
Shipit.stubs(:git_progress_output).returns(true)

command = @commands.fetch

expected = %W(git clone --single-branch --recursive --branch master #{@stack.repo_git_url} #{@stack.git_path})
assert_equal expected, command.args.map(&:to_s)
end

test "#fetch calls git fetch in base_path directory if repository cache do not exist" do
@stack.git_path.stubs(:exist?).returns(false)

Expand Down

0 comments on commit 516558d

Please sign in to comment.