Commit f08d9b28 authored by dearblue's avatar dearblue

Use `git checkout` instead of `git reset`

With this change, if the checkout fails, it will stop with an error.

The purpose is to avoid deleting working branch history when
developing gem.
parent dc15c283
...@@ -279,7 +279,7 @@ module MRuby ...@@ -279,7 +279,7 @@ module MRuby
class Command::Git < Command class Command::Git < Command
attr_accessor :flags attr_accessor :flags
attr_accessor :clone_options, :pull_options, :checkout_options, :reset_options attr_accessor :clone_options, :pull_options, :checkout_options, :checkout_detach_options, :reset_options
def initialize(build) def initialize(build)
super super
...@@ -288,6 +288,7 @@ module MRuby ...@@ -288,6 +288,7 @@ module MRuby
@clone_options = "clone %{flags} %{url} %{dir}" @clone_options = "clone %{flags} %{url} %{dir}"
@pull_options = "--git-dir %{repo_dir}/.git --work-tree %{repo_dir} pull" @pull_options = "--git-dir %{repo_dir}/.git --work-tree %{repo_dir} pull"
@checkout_options = "--git-dir %{repo_dir}/.git --work-tree %{repo_dir} checkout %{checksum_hash}" @checkout_options = "--git-dir %{repo_dir}/.git --work-tree %{repo_dir} checkout %{checksum_hash}"
@checkout_detach_options = "--git-dir %{repo_dir}/.git --work-tree %{repo_dir} checkout --detach %{checksum_hash}"
@reset_options = "--git-dir %{repo_dir}/.git --work-tree %{repo_dir} reset %{checksum_hash}" @reset_options = "--git-dir %{repo_dir}/.git --work-tree %{repo_dir} reset %{checksum_hash}"
end end
...@@ -306,6 +307,11 @@ module MRuby ...@@ -306,6 +307,11 @@ module MRuby
_run checkout_options, { :checksum_hash => checksum_hash, :repo_dir => shellquote(dir) } _run checkout_options, { :checksum_hash => checksum_hash, :repo_dir => shellquote(dir) }
end end
def run_checkout_detach(dir, checksum_hash)
_pp "GIT CHECKOUT DETACH", dir, checksum_hash
_run checkout_detach_options, { :checksum_hash => checksum_hash, :repo_dir => shellquote(dir) }
end
def run_reset_hard(dir, checksum_hash) def run_reset_hard(dir, checksum_hash)
_pp "GIT RESET", dir, checksum_hash _pp "GIT RESET", dir, checksum_hash
_run reset_options, { :checksum_hash => checksum_hash, :repo_dir => shellquote(dir) } _run reset_options, { :checksum_hash => checksum_hash, :repo_dir => shellquote(dir) }
......
...@@ -86,14 +86,13 @@ module MRuby ...@@ -86,14 +86,13 @@ module MRuby
if File.exist?(gemdir) if File.exist?(gemdir)
if $pull_gems if $pull_gems
git.run_pull gemdir, url
# Jump to the top of the branch # Jump to the top of the branch
git.run_checkout(gemdir, branch) git.run_checkout gemdir, branch
git.run_reset_hard gemdir, "origin/#{branch}" git.run_pull gemdir, url
elsif params[:checksum_hash] elsif params[:checksum_hash]
git.run_reset_hard(gemdir, params[:checksum_hash]) git.run_checkout_detach gemdir, params[:checksum_hash]
elsif lock elsif lock
git.run_reset_hard(gemdir, lock['commit']) git.run_checkout_detach gemdir, lock['commit']
end end
else else
options = [params[:options]] || [] options = [params[:options]] || []
...@@ -105,9 +104,9 @@ module MRuby ...@@ -105,9 +104,9 @@ module MRuby
# Jump to the specified commit # Jump to the specified commit
if params[:checksum_hash] if params[:checksum_hash]
git.run_reset_hard gemdir, params[:checksum_hash] git.run_checkout_detach gemdir, params[:checksum_hash]
elsif lock elsif lock
git.run_reset_hard gemdir, lock['commit'] git.run_checkout_detach gemdir, lock['commit']
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment