Handle 'typechange' modification, with special case for symlinks

This commit is contained in:
Nathan Broadbent
2011-12-23 11:46:54 +08:00
parent 504bc91fb8
commit 9b0852de2d

View File

@@ -41,6 +41,7 @@ exit if @changes.size > ENV["gs_max_changes"].to_i
:new => "\e[0;33m", :new => "\e[0;33m",
:ren => "\e[0;34m", :ren => "\e[0;34m",
:cpy => "\e[0;33m", :cpy => "\e[0;33m",
:typ => "\e[0;35m",
:unt => "\e[0;36m", :unt => "\e[0;36m",
:dark => "\e[2;37m", :dark => "\e[2;37m",
:branch => "\e[1m", :branch => "\e[1m",
@@ -92,6 +93,7 @@ puts "%s#%s On branch: %s#{@branch}#{ahead} %s| [%s*%s]%s => $#{ENV["git_env_c
when /D./; [" deleted", :del, :staged] when /D./; [" deleted", :del, :staged]
when /R./; [" renamed", :ren, :staged] when /R./; [" renamed", :ren, :staged]
when /C./; [" copied", :cpy, :staged] when /C./; [" copied", :cpy, :staged]
when /T./; ["typechange", :typ, :staged]
when "??"; [" untracked", :unt, :untracked] when "??"; [" untracked", :unt, :untracked]
end end
@@ -104,6 +106,8 @@ puts "%s#%s On branch: %s#{@branch}#{ahead} %s| [%s*%s]%s => $#{ENV["git_env_c
elsif y == "D" && x != "D" && x != "U" elsif y == "D" && x != "D" && x != "U"
# Don't show deleted 'y' during a merge conflict. # Don't show deleted 'y' during a merge conflict.
@stat_hash[:unstaged] << {:msg => " deleted", :col => :del, :file => file} @stat_hash[:unstaged] << {:msg => " deleted", :col => :del, :file => file}
elsif y == "T"
@stat_hash[:unstaged] << {:msg => "typechange", :col => :typ, :file => file}
end end
end end
@@ -126,16 +130,22 @@ def output_file_group(group)
@e += 1 @e += 1
padding = (@e < 10 && @changes.size >= 10) ? " " : "" padding = (@e < 10 && @changes.size >= 10) ? " " : ""
# Find relative path, i.e. ../../lib/path/to/file
rel_file = relative_path(Dir.pwd, File.join(@project_root, h[:file])) rel_file = relative_path(Dir.pwd, File.join(@project_root, h[:file]))
puts "#{c_group}##{@c[:rst]} #{@c[h[:col]]}#{h[:msg]}:\ puts "#{c_group}##{@c[:rst]} #{@c[h[:col]]}#{h[:msg]}:\
#{padding}#{@c[:dark]} [#{@c[:rst]}#{@e}#{@c[:dark]}] #{c_group}#{rel_file}#{@c[:rst]}" #{padding}#{@c[:dark]} [#{@c[:rst]}#{@e}#{@c[:dark]}] #{c_group}#{rel_file}#{@c[:rst]}"
# Save the ordered list of output files # Save the ordered list of output files
# fetch first file (in the case of oldFile -> newFile) and remove quotes # fetch first file (in the case of oldFile -> newFile) and remove quotes
@output_files << if h[:file] =~ /^"([^\\"]*(\\.[^"]*)*)"/ @output_files << if h[:msg] == "typechange"
# Only use relative paths for 'typechange' modifications.
"~#{rel_file}"
elsif h[:file] =~ /^"([^\\"]*(\\.[^"]*)*)"/
# Handle the regex above..
$1.gsub(/\\(.)/,'\1') $1.gsub(/\\(.)/,'\1')
else else
h[:file].match(/^[^ ]*/)[0] # Else, strip file
h[:file].strip
end end
end end
@@ -162,5 +172,8 @@ end
end end
print "@@filelist@@::" print "@@filelist@@::"
puts @output_files.map{|f| File.join(@project_root, f) }.join("|") puts @output_files.map {|f|
# If file starts with a '~', treat it as a relative path.
# This is important when dealing with symlinks
f.start_with?("~") ? f.sub(/~/, '') : File.join(@project_root, f)
}.join("|")