# # # add_dir "tests/policy-subpolicies" # # add_file "tests/policy-subpolicies/__driver__.lua" # content [6ae43283d064462ce4b6af746f4774d37e394fcc] # # patch "cmd_policy.cc" # from [4ccd62c139a8a66293200a5739f4a52cee056386] # to [589737cc2cd3c94bd860e20327894daa582113e9] # # patch "policy.cc" # from [e68e4275728721bd97b39c69c520f565d8b13eaa] # to [cc6c327953b80828f672f5ad49c1a648a98fb9d2] # ============================================================ --- tests/policy-subpolicies/__driver__.lua 6ae43283d064462ce4b6af746f4774d37e394fcc +++ tests/policy-subpolicies/__driver__.lua 6ae43283d064462ce4b6af746f4774d37e394fcc @@ -0,0 +1,13 @@ + +mtn_setup() + +check(mtn("create_project", "test_project"), 0, false, false) + +check(mtn("create_subpolicy", "test_project.subproject"), 0, false, false) + +check(mtn("create_subpolicy", "test_project.subproject.subsub"), 0, false, false) + + +check(mtn("checkout", "checkout", "--branch=test_project.subproject.__policy__"), 0) + +check(exists("checkout/delegations/subsub")) ============================================================ --- cmd_policy.cc 4ccd62c139a8a66293200a5739f4a52cee056386 +++ cmd_policy.cc 589737cc2cd3c94bd860e20327894daa582113e9 @@ -197,6 +197,7 @@ CMD(create_subpolicy, "create_subpolicy" E(projects.get_project_of_branch(name) .get_policy_branch_policy_of(name, policy_policy, parent_prefix), F("Cannot find parent policy for %s") % prefix); + P(F("Parent policy: %s") % parent_prefix); std::string subprefix; E(prefix() != parent_prefix(), @@ -233,14 +234,14 @@ CMD(create_subpolicy, "create_subpolicy" std::string child_uid; data child_spec; + // Create the new policy branch. create_policy_branch(db, keys, app.lua, app.opts, prefix, admin_keys, child_uid, child_spec); file_id child_spec_id; - { - file_data child_file_dat(child_spec); - calculate_ident(child_file_dat, child_spec_id); - } + file_data child_file_dat(child_spec); + calculate_ident(child_file_dat, child_spec_id); + // Delegate to it in the parent policy branch. policy_changes.files_added.insert(std::make_pair(delegation_file, child_spec_id)); @@ -249,8 +250,46 @@ CMD(create_subpolicy, "create_subpolicy" policy_old_roster, policy_changes, policy_new_revision); - + { + revision_id rev_id; + calculate_ident(policy_new_revision, rev_id); + revision_data rdat; + write_revision(policy_new_revision, rdat); + + + // write to the db + if (!db.file_version_exists(child_spec_id)) + { + db.put_file(child_spec_id, child_file_dat); + } + db.put_revision(rev_id, rdat); + + + // add certs + // Do not use project_t::put_standard_certs here, we don't want the + // branch name to be translated! + date_t date; + if (app.opts.date_given) + date = app.opts.date; + else + date = date_t::now(); + + std::string author = app.opts.author(); + if (author.empty()) + { + if (!app.lua.hook_get_author(branch_name(prefix() + ".__policy__"), + keys.signing_key, author)) + author = keys.signing_key(); + } + utf8 changelog(N_("Create new policy branch.")); + + cert_revision_in_branch(db, keys, rev_id, branch_uid(policy_policy.branch_cert_value)); + cert_revision_changelog(db, keys, rev_id, changelog); + cert_revision_date_time(db, keys, rev_id, date); + cert_revision_author(db, keys, rev_id, author); + } + guard.commit(); } ============================================================ --- policy.cc e68e4275728721bd97b39c69c520f565d8b13eaa +++ policy.cc cc6c327953b80828f672f5ad49c1a648a98fb9d2 @@ -427,7 +427,7 @@ policy_branch::get_nearest_policy(branch my_branch_cert_value, my_committers); return policy->get_nearest_policy(name, policy_policy, policy_prefix, - accumulated_prefix); + prefix()); } bool @@ -439,13 +439,13 @@ policy_revision::get_nearest_policy(bran for (std::map::iterator i = delegations.begin(); i != delegations.end(); ++i) { - std::string mypref(accumulated_prefix + "." + i->first()); + std::string mypref(i->first()); if (name().find(mypref) == 0) { return i->second.get_nearest_policy(name, policy_policy, policy_prefix, - mypref); + ""); } } policy_prefix = branch_prefix(accumulated_prefix);