fast_remote_cache icon indicating copy to clipboard operation
fast_remote_cache copied to clipboard

git reset --hard breaks the hard links

Open dylanahsmith opened this issue 13 years ago • 1 comments

Although the copy.rb script will make the copy into the release directory fast, this time is actually just shifting to the git reset --hard command since it will break all the hard links, even for unchanged files. Breaking hard links equates to copying the file to replace the hard link.

Ideally this would be fixed in git, but as a workaround I found that git reset --mixed #{revision} && git checkout -f . checks out the files without breaking hard links, so actually speeds up deploys when using fast_remote_cache.

Adding the following to config/deploy.rb will speed up deploys by using avoid git reset --hard.

module FastGitSync
  def sync(revision, destination)
    git     = command
    remote  = origin
    branch  = head

    execute = []
    execute << "cd #{destination}"

    execute << "#{git} fetch #{verbose} #{remote} +#{branch}:refs/remotes/#{remote}/#{branch}"

    # Reset the git index
    execute << "#{git} reset #{verbose} --mixed #{revision}"

    # Checkout the index into the work tree
    execute << "#{git} checkout -f ."

    # Remove untracked files
    execute << "#{git} clean #{verbose} -d -x -f"

    execute.join(" && ")
  end
end

set(:source) { Capistrano::Deploy::SCM.new(scm, self).extend(FastGitSync) }

Some conditions from sync where removed for brevity. See the original source for the sync method for details.

Any thoughts on how this change should be integrated into fast_remote_cache?

dylanahsmith avatar Sep 05 '12 23:09 dylanahsmith

Related: https://github.com/brave/brave-browser/issues/20316#issuecomment-1016715519

mherrmann avatar Jan 19 '22 17:01 mherrmann