mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-18 17:36:22 +00:00
feat: hacer fast forward si no hay cambios locales #14533
This commit is contained in:
parent
9ec0dc87a9
commit
f00d6c6d45
2 changed files with 45 additions and 14 deletions
|
@ -1,7 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# Permite traer los cambios desde webhooks
|
||||
|
||||
# Permite traer los cambios desde el repositorio remoto
|
||||
class GitPullJob < ApplicationJob
|
||||
# @param :site [Site]
|
||||
# @param :usuarie [Usuarie]
|
||||
|
@ -12,6 +11,14 @@ class GitPullJob < ApplicationJob
|
|||
|
||||
return if site.repository.up_to_date?
|
||||
|
||||
if site.repository.fast_forward?
|
||||
site.repository.fast_forward!
|
||||
else
|
||||
site.repository.merge(usuarie, message)
|
||||
end
|
||||
|
||||
git_lfs_checkout
|
||||
|
||||
nil
|
||||
end
|
||||
end
|
|
@ -76,12 +76,17 @@ class Site
|
|||
# escribir los cambios
|
||||
rugged.checkout 'HEAD', strategy: :force
|
||||
|
||||
git_sh("git", "lfs", "fetch", "origin", default_branch)
|
||||
# reemplaza los pointers por los archivos correspondientes
|
||||
git_sh("git", "lfs", "checkout")
|
||||
commit
|
||||
end
|
||||
|
||||
# Trae todos los archivos desde LFS
|
||||
#
|
||||
# @return [Boolean]
|
||||
def git_lfs_checkout
|
||||
git_sh('git', 'lfs', 'fetch', 'origin', default_branch)
|
||||
git_sh('git', 'lfs', 'checkout')
|
||||
end
|
||||
|
||||
# El último commit
|
||||
#
|
||||
# @return [Rugged::Commit]
|
||||
|
@ -118,6 +123,25 @@ class Site
|
|||
rugged.merge_analysis(remote_head_commit).include?(:up_to_date)
|
||||
end
|
||||
|
||||
# Detecta si es posible adelantar la historia local a la remota o
|
||||
# necesitamos un merge
|
||||
#
|
||||
# @return [Boolean]
|
||||
def fast_forward?
|
||||
rugged.merge_analysis(remote_head_commit).include?(:fastforward)
|
||||
end
|
||||
|
||||
# Mueve la historia local a la remota
|
||||
#
|
||||
# @see {https://stackoverflow.com/a/27077322}
|
||||
# @return [nil]
|
||||
def fast_forward!
|
||||
rugged.checkout_tree(remote_head_commit)
|
||||
rugged.references.update(rugged.head.resolve, remote_head_commit.oid)
|
||||
|
||||
nil
|
||||
end
|
||||
|
||||
# Guarda los cambios en git
|
||||
#
|
||||
# @param :add [Array] Archivos a agregar
|
||||
|
|
Loading…
Reference in a new issue