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

Closed
drzewiec opened this issue Aug 5, 2019 · 2 comments
Labels
Design Proposal: Accepted. PRs Welcome Overall design approved. You build. We merge Focus: SCM Resources Issues with the git and svn resources Triage: Feature Request Indicates an issue requesting new functionality.

Comments

@drzewiec
Copy link

drzewiec 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.

@drzewiec drzewiec added the Status: Untriaged An issue that has yet to be triaged. label Aug 5, 2019
@tas50 tas50 added Triage: Feature Request Indicates an issue requesting new functionality. and removed Status: Untriaged An issue that has yet to be triaged. labels Sep 9, 2019
@lamont-granquist
Copy link
Contributor

This probably couldn't be the default behavior. There are likely many people who expect the git checkout to be able to be dirtied after being checked out that this would break.

@lamont-granquist lamont-granquist added the Focus: SCM Resources Issues with the git and svn resources label Feb 18, 2020
@tas50
Copy link
Contributor

tas50 commented Nov 16, 2020

If someone would like to build a property of reset_hard_before we'd accept that PR, but this isn't an issue that Chef will be working on directly.

@tas50 tas50 closed this as completed Nov 16, 2020
@tas50 tas50 added the Design Proposal: Accepted. PRs Welcome Overall design approved. You build. We merge label Nov 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Design Proposal: Accepted. PRs Welcome Overall design approved. You build. We merge Focus: SCM Resources Issues with the git and svn resources Triage: Feature Request Indicates an issue requesting new functionality.
Projects
None yet
Development

No branches or pull requests

3 participants