diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb
index 8cb68b1d4..7a5675b4f 100644
--- a/app/controllers/challenges_controller.rb
+++ b/app/controllers/challenges_controller.rb
@@ -198,14 +198,17 @@ class ChallengesController < ApplicationController
         # 测试集变化则需要更新(输入、 输出、 是否隐藏)
         if sets_output != params_output || sets_open != params_hidden || sets_input != params_input || set_score != params_score
           test_set.delete_all unless test_set.blank?
-            params[:test_set].each_with_index do |set, index|
-                TestSet.create(:challenge_id => @challenge.id,
-                               :input => "#{set[:input]}",
-                               :output => "#{set[:output]}",
-                               :is_public => params_hidden[index],
-                               :score => set[:score],
-                               :position => (index + 1))
-            end
+          params[:test_set].each_with_index do |set, index|
+            # last: 末尾匹配, full: 全完匹配
+            match_rule = params[:match_rule] == 'last' ? 'last' : 'full'
+            TestSet.create(:challenge_id => @challenge.id,
+                           :input => "#{set[:input]}",
+                           :output => "#{set[:output]}",
+                           :is_public => params_hidden[index],
+                           :score => set[:score],
+                           :match_rule => "#{match_rule}",
+                           :position => (index + 1))
+          end
           @challenge.update_column(:modify_time, Time.now)
           # 测试集的
           @shixun.myshixuns.update_all(:system_tip => 0)
diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb
index 916f09430..26a7ff8db 100644
--- a/app/controllers/games_controller.rb
+++ b/app/controllers/games_controller.rb
@@ -537,7 +537,7 @@ class GamesController < ApplicationController
     game_challenge.test_sets.each do |test_set|
       input = test_set.input.nil? ? "" : test_set.input.gsub("\r\n", "\n")
       output = test_set.output.nil? ? "" : test_set.output.gsub("\r\n", "\n")
-      test_cases = {:input => input, :output => output}
+      test_cases = {:input => input, :output => output, :matchRule => test_set.match_rule}
       testSet << test_cases
     end
 
@@ -560,6 +560,13 @@ class GamesController < ApplicationController
     # needPortMapping: web类型需要pod端口映射
     br_params[:needPortMapping] = 8080 if @myshixun.mirror_name.include?("Web")
 
+    # 私密仓库的设置
+    secret_rep = @shixun.shixun_secret_repository
+    if secret_rep&.repo_name
+      secretGitUrl = repo_url secret_rep.repo_path
+      br_params.merge({secretGitUrl:  secretGitUrl, secretDir: secret_rep.secret_dir_path})
+    end
+
     # 中间层交互
     uri = "#{shixun_tomcat}/bridge/game/gameEvaluate"
     res = interface_post uri, br_params, 502, "gameEvaluate failed"
diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb
index 79e182fef..ad74b97db 100644
--- a/app/controllers/shixuns_controller.rb
+++ b/app/controllers/shixuns_controller.rb
@@ -473,6 +473,17 @@ class ShixunsController < ApplicationController
 						@shixun.shixun_service_configs.create!(config) if name.present?
 					end
 				end
+				# 添加第二仓库
+				if params[:is_secret_repository]
+					add_secret_repositoy
+				else
+					# 如果有仓库,就要删
+					if @shixun.shixun_secret_repository&.repo_name
+						GitService.delete_repository(repo_path: @shixun.shixun_secret_repository.repo_path)
+						@shixun.shixun_secret_repository.destroy
+					end
+				end
+
 			rescue Exception => e
 				uid_logger_error(e.message)
 				tip_exception("实训保存失败")
@@ -819,6 +830,29 @@ class ShixunsController < ApplicationController
 		end
 	end
 
+	# 设置私密版本库的在tpm中的目录
+	def set_secret_dir
+		raise("设置路径不能为空") if params[:secret_dir_path].blank?
+		@shixun.shixun_secret_repository.update_attribute(:secret_dir_path, params[:secret_dir_path])
+		normal_status("设置成功")
+	end
+
+	def secret_repository
+		begin
+			@repo_path = @shixun.shixun_secret_repository&.repo_path
+			@repo_url = repo_url @repo_path
+			@trees = GitService.file_tree(repo_path: @repo_path, path: params[:path])
+			logger.info("#11@@#@#@#@111#@@@@###{@trees}")
+			if @trees
+				logger.info("#@@#@#@#@#@@@@###{@trees.try(:count)}")
+				@latest_commit = [GitService.commits(repo_path: @repo_path).first]
+				Rails.logger.info("########## #{@latest_commit}")
+			end
+		rescue Exception => e
+			logger.error(e.message)
+		end
+	end
+
 	include GitCommon
 
 	def update_file
@@ -990,4 +1024,13 @@ private
 		modify_shixun = ShixunModify.exists?(:myshixun_id => current_myshixun.id, :shixun_id => @shixun.id, :status => 1)
 		games.size != min_challenges.size || modify_shixun
 	end
+
+	# 添加私密仓库
+	def add_secret_repositoy
+		# 防止跟tpm版本库重名,加了前缀secret
+		repo_path = repo_namespace(current_user.login, "secret_#{@shixun.identifier}")
+		GitService.add_repository(repo_path: repo_path)
+		@shixun.shixun_secret_repository.create!(repo_name: repo_path.split(".")[0])
+	end
+
 end
diff --git a/app/models/shixun.rb b/app/models/shixun.rb
index 9ad3cbcdf..83d97f822 100644
--- a/app/models/shixun.rb
+++ b/app/models/shixun.rb
@@ -38,6 +38,9 @@ class Shixun < ApplicationRecord
 
   has_one :shixun_info, dependent: :destroy
 
+  # 第二版本库
+  has_one :shixun_secret_repository, dependent: :destroy
+
   belongs_to :user
   # 实训服务配置
   has_many :shixun_service_configs, :dependent => :destroy
diff --git a/app/models/shixun_secret_repository.rb b/app/models/shixun_secret_repository.rb
new file mode 100644
index 000000000..699c6dd30
--- /dev/null
+++ b/app/models/shixun_secret_repository.rb
@@ -0,0 +1,11 @@
+class ShixunSecretRepository < ApplicationRecord
+  # repo_name: 仓库名
+  # secret_dir_name: 在tpm仓库的那个目录下
+
+  belongs_to :shixun
+
+  def repo_path
+    "#{repo_name}.git"
+  end
+
+end
diff --git a/app/models/test_set.rb b/app/models/test_set.rb
index 148cb8720..7772a3a00 100644
--- a/app/models/test_set.rb
+++ b/app/models/test_set.rb
@@ -1,2 +1,3 @@
 class TestSet < ApplicationRecord
+  # match_rule: 匹配规则: full: 完全匹配, last: 末尾匹配
 end
diff --git a/app/views/shixuns/secret_repository.json.jbuilder b/app/views/shixuns/secret_repository.json.jbuilder
new file mode 100644
index 000000000..51f774fd8
--- /dev/null
+++ b/app/views/shixuns/secret_repository.json.jbuilder
@@ -0,0 +1,7 @@
+json.trees @trees
+
+if @trees.present?
+  json.partial! 'shixuns/commit', locals: { commits: @latest_commit }
+end
+
+json.git_url @repo_url
\ No newline at end of file
diff --git a/config/routes.rb b/config/routes.rb
index 5cf74c29a..0d6e108ad 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -197,6 +197,8 @@ Rails.application.routes.draw do
         get :get_script_contents
         get :get_custom_script
         post :repository
+        post :secret_repository
+        post :set_secret_dir
         post :commits
         post :file_content
         post :update_file
diff --git a/db/migrate/20190909061930_create_shixun_secret_repositories.rb b/db/migrate/20190909061930_create_shixun_secret_repositories.rb
new file mode 100644
index 000000000..5526869f8
--- /dev/null
+++ b/db/migrate/20190909061930_create_shixun_secret_repositories.rb
@@ -0,0 +1,10 @@
+class CreateShixunSecretRepositories < ActiveRecord::Migration[5.2]
+  def change
+    create_table :shixun_secret_repositories do |t|
+      t.references :shixun
+      t.string :repo_name
+      t.string :secret_dir_path
+      t.timestamps
+    end
+  end
+end
diff --git a/db/migrate/20190909072626_add_match_rule_for_test_sets.rb b/db/migrate/20190909072626_add_match_rule_for_test_sets.rb
new file mode 100644
index 000000000..2d9d53f0f
--- /dev/null
+++ b/db/migrate/20190909072626_add_match_rule_for_test_sets.rb
@@ -0,0 +1,7 @@
+class AddMatchRuleForTestSets < ActiveRecord::Migration[5.2]
+  def change
+    add_column :test_sets, :match_rule, :string
+    TestSet.update_all(match_rule: 'full')
+
+  end
+end
diff --git a/spec/models/shixun_secret_repository_spec.rb b/spec/models/shixun_secret_repository_spec.rb
new file mode 100644
index 000000000..ed06914ae
--- /dev/null
+++ b/spec/models/shixun_secret_repository_spec.rb
@@ -0,0 +1,5 @@
+require 'rails_helper'
+
+RSpec.describe ShixunSecretRepository, type: :model do
+  pending "add some examples to (or delete) #{__FILE__}"
+end