@@ -90,12 +90,29 @@ def setup
9090 @target = nil
9191 pend "No git" unless system ( "git --version" , out : IO ::NULL )
9292 @testdir = Dir . mktmpdir ( "sync" )
93- @git_config = %W" HOME GIT_CONFIG_GLOBAL " . each_with_object ( { } ) { |k , c | c [ k ] = ENV [ k ] }
93+ user , email = "Ruby" , "[email protected] " 94+ @git_config = %W" HOME USER GIT_CONFIG_GLOBAL GNUPGHOME " . each_with_object ( { } ) { |k , c | c [ k ] = ENV [ k ] }
9495 ENV [ "HOME" ] = @testdir
96+ ENV [ "USER" ] = user
97+ ENV [ "GNUPGHOME" ] = @testdir + '/.gnupg'
98+ expire = EnvUtil . apply_timeout_scale ( 30 ) . to_i
99+ # Generate a new unprotected key with default parameters that
100+ # expires after 30 seconds.
101+ if @gpgsign = system ( *%w" gpg --quiet --batch --passphrase " , "" ,
102+ "--quick-generate-key" , email , *%W" default default seconds=#{ expire } " )
103+ # Fetch the generated public key.
104+ signingkey = IO . popen ( %W" gpg --quiet --list-public-key #{ email } " , &:read ) [ /^pub .*\n +\K \h +/ ]
105+ end
95106 ENV [ "GIT_CONFIG_GLOBAL" ] = @testdir + "/gitconfig"
96- git ( *
%W" config --global user.email [email protected] " ) 97- git ( *%W" config --global user.name " , "Ruby" )
107+ git ( *%W" config --global user.email " , email )
108+ git ( *%W" config --global user.name " , user )
98109 git ( *%W" config --global init.defaultBranch default " )
110+ if signingkey
111+ git ( *%W" config --global user.signingkey " , signingkey )
112+ git ( *%W" config --global commit.gpgsign true " )
113+ git ( *%W" config --global gpg.program gpg " )
114+ git ( *%W" config --global log.showSignature true " )
115+ end
99116 @target = "sync-test"
100117 SyncDefaultGems ::REPOSITORIES [ @target ] = [ "ruby/#{ @target } " , "default" ]
101118 @sha = { }
@@ -129,6 +146,9 @@ def setup
129146
130147 def teardown
131148 if @target
149+ if @gpgsign
150+ system ( *%W" gpgconf --kill all " )
151+ end
132152 Dir . chdir ( @origdir )
133153 SyncDefaultGems ::REPOSITORIES . delete ( @target )
134154 ENV . update ( @git_config )
@@ -168,7 +188,7 @@ def git(*commands, **opts)
168188 end
169189
170190 def top_commit ( dir , format : "%H" )
171- IO . popen ( %W[ git log --format=#{ format } -1 ] , chdir : dir , &:read ) &.chomp
191+ IO . popen ( %W[ git log --no-show-signature -- format=#{ format } -1 ] , chdir : dir , &:read ) &.chomp
172192 end
173193
174194 def assert_sync ( commits = true , success : true , editor : nil )
0 commit comments