Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ jobs:
with:
key: partition-${{ matrix.partition }}
- uses: taiki-e/install-action@nextest
- uses: taiki-e/install-action@v2
with:
tool: jj-cli
- name: Build
run: cargo build
- name: Run tests
Expand Down
6 changes: 5 additions & 1 deletion crates/dropshot-api-manager/src/cmd/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,14 @@ fn dump_structure<T: AsRawFiles>(
for (version, files) in info.versions() {
println!(" version {}:", version);
for api_spec in files.as_raw_files() {
let version_str = api_spec
.version()
.map(|v| v.to_string())
.unwrap_or_else(|| "unparseable".to_string());
println!(
" file {} (v{})",
api_spec.spec_file_name().path(),
api_spec.version()
version_str
);
}
}
Expand Down
22 changes: 20 additions & 2 deletions crates/dropshot-api-manager/src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,23 @@ pub enum CommitHashParseError {
InvalidHex(hex::FromHexError),
}

/// Given a revision, return its merge base with HEAD
/// Given a revision, return its merge base with the current working state.
///
/// If we're in the middle of a merge (MERGE_HEAD exists), we use MERGE_HEAD
/// instead of HEAD for the merge base calculation. This is important because
/// during a merge conflict, HEAD points to our branch while MERGE_HEAD points
/// to the branch being merged in. Using MERGE_HEAD ensures we see blessed
/// documents from the incoming branch.
pub fn git_merge_base_head(
repo_root: &Utf8Path,
revision: &GitRevision,
) -> anyhow::Result<GitRevision> {
// Check if we're in a merge state. If so, use MERGE_HEAD instead of HEAD.
let base_ref =
if git_merge_head_exists(repo_root) { "MERGE_HEAD" } else { "HEAD" };

let mut cmd = git_start(repo_root);
cmd.arg("merge-base").arg("--all").arg("HEAD").arg(revision.as_str());
cmd.arg("merge-base").arg("--all").arg(base_ref).arg(revision.as_str());
let label = cmd_label(&cmd);
let stdout = do_run(&mut cmd)?;
let stdout = stdout.trim();
Expand All @@ -110,6 +120,14 @@ pub fn git_merge_base_head(
Ok(GitRevision::from(stdout.to_owned()))
}

/// Returns true if MERGE_HEAD exists, indicating we're in the middle of a
/// merge.
fn git_merge_head_exists(repo_root: &Utf8Path) -> bool {
let mut cmd = git_start(repo_root);
cmd.args(["rev-parse", "--verify", "--quiet", "MERGE_HEAD"]);
matches!(cmd.status(), Ok(status) if status.success())
}

/// List files recursively under some path `path` in Git revision `revision`.
pub fn git_ls_tree(
repo_root: &Utf8Path,
Expand Down
Loading