Merge branch 'fix-masterlist-update' into dev

This commit is contained in:
Oliver Hamlet
2017-06-17 15:53:37 +01:00
5 changed files with 29 additions and 11 deletions
+3
View File
@@ -45,6 +45,9 @@ before_script:
script:
- make all
# Some tests call Git, so set a user
- git config --global user.email "travis@ci"
- git config --global user.name "Travis"
- ./loot_api_internals_tests
- ./loot_api_tests
+3
View File
@@ -47,6 +47,9 @@ build:
test_script:
- cd %APPVEYOR_BUILD_FOLDER%\build\%CONFIGURATION%
# Some tests call Git, so set a user
- git config --global user.email "appveyor@ci"
- git config --global user.name "AppVeyor"
- loot_api_internals_tests.exe --gtest_output=xml:loot_api_internals_tests.xml
- loot_api_tests.exe --gtest_output=xml:loot_api_tests.xml
+1 -1
View File
@@ -216,7 +216,7 @@ void GitHelper::CheckoutNewBranch(const std::string& remote, const std::string&
// Create a branch.
BOOST_LOG_TRIVIAL(trace) << "Creating the new branch.";
Call(git_commit_lookup(&data_.commit, data_.repo, commit_id));
Call(git_branch_create(&data_.reference, data_.repo, branch.c_str(), data_.commit, 0));
Call(git_branch_create(&data_.reference, data_.repo, branch.c_str(), data_.commit, 1));
// Set upstream.
BOOST_LOG_TRIVIAL(trace) << "Setting the upstream for the new branch.";
+2 -2
View File
@@ -181,8 +181,8 @@ bool Masterlist::Update(const boost::filesystem::path& path, const std::string&
// The local branch can't be easily merged. Best just to delete and recreate it.
BOOST_LOG_TRIVIAL(trace) << "Local branch cannot be easily merged with remote branch.";
BOOST_LOG_TRIVIAL(trace) << "Deleting the local branch.";
git.Call(git_branch_delete(git.GetData().reference));
BOOST_LOG_TRIVIAL(trace) << "Detaching HEAD so that the branch can be recreated.";
git.Call(git_repository_detach_head(git.GetData().repo));
// Need to free ref before calling git.CheckoutNewBranch()
git_reference_free(git.GetData().reference);
+20 -8
View File
@@ -71,19 +71,19 @@ INSTANTIATE_TEST_CASE_P(,
GameType::fo4,
GameType::tes5se));
TEST_P(MasterlistTest, updateWithSeparateParametersShouldThrowIfAnInvalidPathIsGiven) {
TEST_P(MasterlistTest, updateShouldThrowIfAnInvalidPathIsGiven) {
Masterlist masterlist;
EXPECT_THROW(masterlist.Update(";//\?", repoUrl, repoBranch), boost::filesystem::filesystem_error);
}
TEST_P(MasterlistTest, updateWithSeparateParametersShouldThrowIfABlankPathIsGiven) {
TEST_P(MasterlistTest, updateShouldThrowIfABlankPathIsGiven) {
Masterlist masterlist;
EXPECT_THROW(masterlist.Update("", repoUrl, repoBranch), boost::filesystem::filesystem_error);
}
TEST_P(MasterlistTest, updateWithSeparateParametersShouldThrowIfABranchThatDoesNotExistIsGiven) {
TEST_P(MasterlistTest, updateShouldThrowIfABranchThatDoesNotExistIsGiven) {
Masterlist masterlist;
EXPECT_THROW(masterlist.Update(masterlistPath,
@@ -91,13 +91,13 @@ TEST_P(MasterlistTest, updateWithSeparateParametersShouldThrowIfABranchThatDoesN
"missing-branch"), std::system_error);
}
TEST_P(MasterlistTest, updateWithSeparateParametersShouldThrowIfABlankBranchIsGiven) {
TEST_P(MasterlistTest, updateShouldThrowIfABlankBranchIsGiven) {
Masterlist masterlist;
EXPECT_THROW(masterlist.Update(masterlistPath, repoUrl, ""), std::invalid_argument);
}
TEST_P(MasterlistTest, updateWithSeparateParametersShouldThrowIfAUrlThatDoesNotExistIsGiven) {
TEST_P(MasterlistTest, updateShouldThrowIfAUrlThatDoesNotExistIsGiven) {
Masterlist masterlist;
EXPECT_THROW(masterlist.Update(masterlistPath,
@@ -105,19 +105,19 @@ TEST_P(MasterlistTest, updateWithSeparateParametersShouldThrowIfAUrlThatDoesNotE
repoBranch), std::system_error);
}
TEST_P(MasterlistTest, updateWithSeparateParametersShouldThrowIfABlankUrlIsGiven) {
TEST_P(MasterlistTest, updateShouldThrowIfABlankUrlIsGiven) {
Masterlist masterlist;
EXPECT_THROW(masterlist.Update(masterlistPath, "", repoBranch), std::invalid_argument);
}
TEST_P(MasterlistTest, updateWithSeparateParametersShouldReturnTrueIfNoMasterlistExists) {
TEST_P(MasterlistTest, updateShouldReturnTrueIfNoMasterlistExists) {
Masterlist masterlist;
EXPECT_TRUE(masterlist.Update(masterlistPath,
repoUrl,
repoBranch));
}
TEST_P(MasterlistTest, updateWithSeparateParametersShouldReturnFalseIfAnUpToDateMasterlistExists) {
TEST_P(MasterlistTest, updateShouldReturnFalseIfAnUpToDateMasterlistExists) {
Masterlist masterlist;
EXPECT_TRUE(masterlist.Update(masterlistPath,
@@ -129,6 +129,18 @@ TEST_P(MasterlistTest, updateWithSeparateParametersShouldReturnFalseIfAnUpToDate
repoBranch));
}
TEST_P(MasterlistTest, updateShouldDiscardLocalHistoryIfRemoteHistoryIsDifferent) {
Masterlist masterlist;
ASSERT_TRUE(masterlist.Update(masterlistPath, repoUrl, repoBranch));
auto testPath = boost::filesystem::current_path();
boost::filesystem::current_path(masterlistPath.parent_path());
system("git commit --amend -m \"changing local history\"");
boost::filesystem::current_path(testPath);
EXPECT_TRUE(masterlist.Update(masterlistPath, repoUrl, repoBranch));
}
TEST_P(MasterlistTest, getInfoShouldThrowIfNoMasterlistExistsAtTheGivenPath) {
Masterlist masterlist;
EXPECT_THROW(masterlist.GetInfo(masterlistPath, false), FileAccessError);