Skip to content

Commit

Permalink
Support for git config --global gist.private yes
Browse files Browse the repository at this point in the history
I don't want gisters to accidentally create public gists of stuff that
they thought would be private.
  • Loading branch information
ConradIrwin committed May 3, 2013
1 parent 63300c1 commit 7be4a12
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion bin/gist
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ begin
:html_url
end

options[:public] = !options.delete(:private)
options[:public] = Gist.should_be_public?(options)

if options[:paste]
puts Gist.gist(Gist.paste, options)
Expand Down
9 changes: 9 additions & 0 deletions lib/gist.rb
Original file line number Diff line number Diff line change
Expand Up @@ -343,4 +343,13 @@ def auth_token_file
File.expand_path "~/.gist"
end
end

def legacy_private_gister?
return unless which('git')
`git config --global gist.private` =~ /\Ayes|1|true|on\z/i
end

def should_be_public?(options={})
!(options[:private] || Gist.legacy_private_gister?)
end
end
18 changes: 18 additions & 0 deletions spec/gist_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
describe Gist do

describe "should_be_public?" do
it "should return false if -p is specified" do
Gist.should_be_public?(private: true).should be_false
end

it "should return false if legacy_private_gister?" do
Gist.should_receive(:legacy_private_gister?).and_return(true)
Gist.should_be_public?.should be_false
end

it "should return true by default" do
Gist.should_be_public?.should be_true
end
end

end

0 comments on commit 7be4a12

Please sign in to comment.