From 2bed57fdbbe1860936616a76404dd2454b3173fd Mon Sep 17 00:00:00 2001 From: Thierry Date: Fri, 17 Feb 2017 14:42:58 +0800 Subject: [PATCH 1/3] fix git log message character issue --- .idea/.rakeTasks | 7 ++ .idea/encodings.xml | 6 + .idea/misc.xml | 29 +++++ .idea/modules.xml | 8 ++ .idea/ruby-git.iml | 13 ++ .idea/vcs.xml | 6 + .idea/workspace.xml | 289 ++++++++++++++++++++++++++++++++++++++++++++ lib/git/lib.rb | 4 - 8 files changed, 358 insertions(+), 4 deletions(-) create mode 100644 .idea/.rakeTasks create mode 100644 .idea/encodings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/ruby-git.iml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml diff --git a/.idea/.rakeTasks b/.idea/.rakeTasks new file mode 100644 index 00000000..9280a0fd --- /dev/null +++ b/.idea/.rakeTasks @@ -0,0 +1,7 @@ + + diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 00000000..97626ba4 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 00000000..76fa42fd --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 00000000..20f2f098 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/ruby-git.iml b/.idea/ruby-git.iml new file mode 100644 index 00000000..4e7e8910 --- /dev/null +++ b/.idea/ruby-git.iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..94a25f7f --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 00000000..0160caea --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,289 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + DEFINITION_ORDER + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1486609402303 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/lib/git/lib.rb b/lib/git/lib.rb index 777e42ea..118b58f1 100644 --- a/lib/git/lib.rb +++ b/lib/git/lib.rb @@ -859,10 +859,6 @@ def meets_required_version? def command_lines(cmd, opts = [], chdir = true, redirect = '') cmd_op = command(cmd, opts, chdir) - op = cmd_op.encode("UTF-8", "binary", { - :invalid => :replace, - :undef => :replace - }) op.split("\n") end From 22fbcb5a24911cba0b7ca8e9d188cfe5b9bfca90 Mon Sep 17 00:00:00 2001 From: Thierry Date: Fri, 17 Feb 2017 14:47:12 +0800 Subject: [PATCH 2/3] fix git log message character issue --- lib/git/lib.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/git/lib.rb b/lib/git/lib.rb index 118b58f1..a8b719c2 100644 --- a/lib/git/lib.rb +++ b/lib/git/lib.rb @@ -859,7 +859,7 @@ def meets_required_version? def command_lines(cmd, opts = [], chdir = true, redirect = '') cmd_op = command(cmd, opts, chdir) - op.split("\n") + cmd_op.split("\n") end # Takes the current git's system ENV variables and store them. From a28d18fb762add98463334df0124d3056cce9c4e Mon Sep 17 00:00:00 2001 From: Thierry Date: Thu, 15 Jun 2017 11:44:14 +0800 Subject: [PATCH 3/3] =?UTF-8?q?add=20=E2=80=94track=20for=20checkout=20com?= =?UTF-8?q?mand?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + .idea/.rakeTasks | 7 -- .idea/encodings.xml | 6 - .idea/misc.xml | 29 ----- .idea/modules.xml | 8 -- .idea/ruby-git.iml | 13 -- .idea/vcs.xml | 6 - .idea/workspace.xml | 289 -------------------------------------------- lib/git/lib.rb | 53 ++++---- 9 files changed, 28 insertions(+), 384 deletions(-) delete mode 100644 .idea/.rakeTasks delete mode 100644 .idea/encodings.xml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/ruby-git.iml delete mode 100644 .idea/vcs.xml delete mode 100644 .idea/workspace.xml diff --git a/.gitignore b/.gitignore index 8394ee1d..4a858b8f 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ *.kpf *.sw? .DS_Store +.idea coverage pkg rdoc diff --git a/.idea/.rakeTasks b/.idea/.rakeTasks deleted file mode 100644 index 9280a0fd..00000000 --- a/.idea/.rakeTasks +++ /dev/null @@ -1,7 +0,0 @@ - - diff --git a/.idea/encodings.xml b/.idea/encodings.xml deleted file mode 100644 index 97626ba4..00000000 --- a/.idea/encodings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 76fa42fd..00000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 20f2f098..00000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/ruby-git.iml b/.idea/ruby-git.iml deleted file mode 100644 index 4e7e8910..00000000 --- a/.idea/ruby-git.iml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7f..00000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml deleted file mode 100644 index 0160caea..00000000 --- a/.idea/workspace.xml +++ /dev/null @@ -1,289 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - true - DEFINITION_ORDER - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1486609402303 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/lib/git/lib.rb b/lib/git/lib.rb index a8b719c2..9f6f7486 100644 --- a/lib/git/lib.rb +++ b/lib/git/lib.rb @@ -148,7 +148,7 @@ def full_log_commits(opts={}) end def revparse(string) - return string if string =~ /^[A-Fa-f0-9]{40}$/ # passing in a sha - just no-op it + return string if string =~ /^[A-Fa-f0-9]{40}$/ # passing in a sha - just no-op it rev = ['head', 'remotes', 'tags'].map do |d| File.join(@git_dir, 'refs', d, string) end.find do |path| @@ -179,9 +179,9 @@ def commit_data(sha) def process_commit_data(data, sha = nil, indent = 4) hsh = { - 'sha' => sha, - 'message' => '', - 'parent' => [] + 'sha' => sha, + 'message' => '', + 'parent' => [] } loop do @@ -196,7 +196,7 @@ def process_commit_data(data, sha = nil, indent = 4) end end - hsh['message'] = data.collect {|line| line[indent..-1]}.join("\n") + "\n" + hsh['message'] = data.collect { |line| line[indent..-1] }.join("\n") + "\n" return hsh end @@ -209,8 +209,8 @@ def tag_data(name) def process_tag_data(data, name, indent=4) hsh = { - 'name' => name, - 'message' => '' + 'name' => name, + 'message' => '' } loop do @@ -221,7 +221,7 @@ def process_tag_data(data, name, indent=4) hsh[key] = value.join(' ') end - hsh['message'] = data.collect {|line| line[indent..-1]}.join("\n") + "\n" + hsh['message'] = data.collect { |line| line[indent..-1] }.join("\n") + "\n" return hsh end @@ -408,14 +408,14 @@ def ls_files(location=nil) def ls_remote(location=nil) location ||= '.' - Hash.new{ |h,k| h[k] = {} }.tap do |hsh| + Hash.new { |h, k| h[k] = {} }.tap do |hsh| command_lines('ls-remote', [location], false).each do |line| (sha, info) = line.split("\t") (ref, type, name) = info.split('/', 3) type ||= 'head' type = 'branches' if type == 'heads' value = {:ref => ref, :sha => sha} - hsh[type].update( name.nil? ? value : { name => value }) + hsh[type].update(name.nil? ? value : {name => value}) end end end @@ -515,7 +515,7 @@ def global_config_set(name, value) # # @param [String,Array] paths files paths to be added to the repository # @param [Hash] options - def add(paths='.',options={}) + def add(paths='.', options={}) arr_opts = [] arr_opts << '--all' if options[:all] @@ -531,7 +531,7 @@ def add(paths='.',options={}) end def remove(path = '.', opts = {}) - arr_opts = ['-f'] # overrides the up-to-date check by default + arr_opts = ['-f'] # overrides the up-to-date check by default arr_opts << ['-r'] if opts[:recursive] arr_opts << ['--cached'] if opts[:cached] arr_opts << '--' @@ -638,6 +638,7 @@ def branch_delete(branch) def checkout(branch, opts = {}) arr_opts = [] arr_opts << '-b' if opts[:new_branch] || opts[:b] + arr_opts << '--track' if opts[:track] || opts[:t] arr_opts << '--force' if opts[:force] || opts[:f] arr_opts << branch @@ -706,7 +707,7 @@ def tag(name, *opts) opts = opts.last.instance_of?(Hash) ? opts.last : {} if (opts[:a] || opts[:annotate]) && !(opts[:m] || opts[:message]) - raise "Can not create an [:a|:annotate] tag without the precense of [:m|:message]." + raise "Can not create an [:a|:annotate] tag without the precense of [:m|:message]." end arr_opts = [] @@ -736,7 +737,7 @@ def push(remote, branch = 'master', opts = {}) opts = {:tags => opts} if [true, false].include?(opts) arr_opts = [] - arr_opts << '--force' if opts[:force] || opts[:f] + arr_opts << '--force' if opts[:force] || opts[:f] arr_opts << remote command('push', arr_opts + [branch]) @@ -751,7 +752,7 @@ def tag_sha(tag_name) head = File.join(@git_dir, 'refs', 'tags', tag_name) return File.read(head).chomp if File.exist?(head) - command('show-ref', ['--tags', '-s', tag_name]) + command('show-ref', ['--tags', '-s', tag_name]) end def repack @@ -838,7 +839,7 @@ def archive(sha, file = nil, opts = {}) def current_command_version output = command('version', [], false) version = output[/\d+\.\d+(\.\d+)+/] - version.split('.').collect {|i| i.to_i} + version.split('.').collect { |i| i.to_i } end def required_command_version @@ -846,7 +847,7 @@ def required_command_version end def meets_required_version? - (self.current_command_version <=> self.required_command_version) >= 0 + (self.current_command_version <=> self.required_command_version) >= 0 end @@ -904,9 +905,9 @@ def command(cmd, opts = [], chdir = true, redirect = '', &block) global_opts << "--git-dir=#{@git_dir}" if !@git_dir.nil? global_opts << "--work-tree=#{@git_work_dir}" if !@git_work_dir.nil? - opts = [opts].flatten.map {|s| escape(s) }.join(' ') + opts = [opts].flatten.map { |s| escape(s) }.join(' ') - global_opts = global_opts.flatten.map {|s| escape(s) }.join(' ') + global_opts = global_opts.flatten.map { |s| escape(s) }.join(' ') git_cmd = "#{Git::Base.config.binary_path} #{global_opts} #{cmd} #{opts} #{redirect} 2>&1" @@ -947,12 +948,12 @@ def diff_as_hash(diff_command, opts=[]) mode_src, mode_dest, sha_src, sha_dest, type = info.split memo[file] = { - :mode_index => mode_dest, - :mode_repo => mode_src.to_s[1, 7], - :path => file, - :sha_repo => sha_src, - :sha_index => sha_dest, - :type => type + :mode_index => mode_dest, + :mode_repo => mode_src.to_s[1, 7], + :path => file, + :sha_repo => sha_src, + :sha_index => sha_dest, + :type => type } memo @@ -996,7 +997,7 @@ def run_command(git_cmd, &block) end def escape(s) - return "'#{s && s.to_s.gsub('\'','\'"\'"\'')}'" if RUBY_PLATFORM !~ /mingw|mswin/ + return "'#{s && s.to_s.gsub('\'', '\'"\'"\'')}'" if RUBY_PLATFORM !~ /mingw|mswin/ # Keeping the old escape format for windows users escaped = s.to_s.gsub('\'', '\'\\\'\'')