Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

git resource does not clean working directory if there are uncommitted changes #8793

Open
drzewiec opened this issue Aug 5, 2019 · 0 comments

Comments

@drzewiec
Copy link

commented Aug 5, 2019

Description

According to the git resource docs (https://docs.chef.io/resource_git.html), the :sync action will hard reset and discard any untracked changes. This is true, but only if there are committed changes locally. Any uncommitted changes will cause the resource to report up-to-date, even though one would expect it to sync the source repository to overwrite those changes.

Chef Version

14.4.56, but looking at the source code in master this appears to not be fixed even in the latest version.

Platform Version

Linux

Replication Case

  1. Use git resource to sync some repo to a test machine
  2. Make a change to the copy of the repo on the test machine (can be either modifying an existing file or adding a new one)
  3. chef-client will not do anything to revert those changes, unless you commit them locally

Relevant Code

def action_sync
if existing_git_clone?
logger.trace "#{new_resource} current revision: #{current_resource.revision} target revision: #{target_revision}"
unless current_revision_matches_target_revision?
fetch_updates
enable_submodules
logger.info "#{new_resource} updated to revision #{target_revision}"
end
add_remotes
else
action_checkout
end
end

This code checks current_revision_matches_target_revision which is good, but since uncommitted changes don't show up in a git rev-parse HEAD (which is how current_revision gets set) they will not trigger this check. Something else needs to be added, perhaps parsing the output of git status.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.