Skip to content

Commit

Permalink
Merge pull request #396 from igor-alexandrov/track-uncommitted-changes
Browse files Browse the repository at this point in the history
Log uncommitted changes during deploy
  • Loading branch information
djmb committed Jul 25, 2023
2 parents edcfc77 + d414253 commit 752ff53
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
8 changes: 7 additions & 1 deletion lib/mrsk/cli/build.rb
Expand Up @@ -17,9 +17,15 @@ def push
verify_local_dependencies
run_hook "pre-build"

if (uncommitted_changes = Mrsk::Utils.uncommitted_changes).present?
say "The following paths have uncommitted changes:\n #{uncommitted_changes}", :yellow
end

run_locally do
begin
MRSK.with_verbosity(:debug) { execute *MRSK.builder.push }
MRSK.with_verbosity(:debug) do
execute *MRSK.builder.push
end
rescue SSHKit::Command::Failed => e
if e.message =~ /(no builder)|(no such file or directory)/
error "Missing compatible builder, so creating a new one first"
Expand Down
2 changes: 1 addition & 1 deletion lib/mrsk/configuration.rb
Expand Up @@ -253,7 +253,7 @@ def role_names
def git_version
@git_version ||=
if system("git rev-parse")
uncommitted_suffix = `git status --porcelain`.strip.present? ? "_uncommitted_#{SecureRandom.hex(8)}" : ""
uncommitted_suffix = Mrsk::Utils.uncommitted_changes.present? ? "_uncommitted_#{SecureRandom.hex(8)}" : ""

"#{`git rev-parse HEAD`.strip}#{uncommitted_suffix}"
else
Expand Down
4 changes: 4 additions & 0 deletions lib/mrsk/utils.rb
Expand Up @@ -93,4 +93,8 @@ def abbreviate_version(version)
end
end
end

def uncommitted_changes
`git status --porcelain`.strip
end
end
4 changes: 2 additions & 2 deletions test/configuration_test.rb
Expand Up @@ -84,15 +84,15 @@ class ConfigurationTest < ActiveSupport::TestCase
ENV.delete("VERSION")

@config.expects(:`).with("git rev-parse HEAD").returns("git-version")
@config.expects(:`).with("git status --porcelain").returns("")
Mrsk::Utils.expects(:uncommitted_changes).returns("")
assert_equal "git-version", @config.version
end

test "version from git uncommitted" do
ENV.delete("VERSION")

@config.expects(:`).with("git rev-parse HEAD").returns("git-version")
@config.expects(:`).with("git status --porcelain").returns("M file\n")
Mrsk::Utils.expects(:uncommitted_changes).returns("M file\n")
assert_match /^git-version_uncommitted_[0-9a-f]{16}$/, @config.version
end

Expand Down
10 changes: 10 additions & 0 deletions test/utils_test.rb
Expand Up @@ -61,4 +61,14 @@ class UtilsTest < ActiveSupport::TestCase
assert_equal "\"https://example.com/\\$2\"",
Mrsk::Utils.escape_shell_value("https://example.com/$2")
end

test "uncommitted changes exist" do
Mrsk::Utils.expects(:`).with("git status --porcelain").returns("M file\n")
assert_equal "M file", Mrsk::Utils.uncommitted_changes
end

test "uncommitted changes do not exist" do
Mrsk::Utils.expects(:`).with("git status --porcelain").returns("")
assert_equal "", Mrsk::Utils.uncommitted_changes
end
end

0 comments on commit 752ff53

Please sign in to comment.