Skip to content

Commit

Permalink
Various improvements (#11)
Browse files Browse the repository at this point in the history
* Issues can link to PRs

* Add support for hard reset when merging ref solution

* Add quest tests
  • Loading branch information
willcrichton authored Aug 31, 2024
1 parent 1cc3883 commit e85ab23
Show file tree
Hide file tree
Showing 8 changed files with 836 additions and 221 deletions.
116 changes: 104 additions & 12 deletions assets/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,37 @@ code, pre {
position: relative;
}

#refresh {
position: absolute;
top: 1rem;
right: 1rem;
.error {
border: 2px solid rgb(226, 33, 33);
border-radius: 8px;
padding: 0.5rem 1rem;
margin: 2rem 0;

> div {
margin-bottom: 1rem;
}

.action {
font-weight: bold;
}

pre {
background-color: #eee;
padding: 0.25rem 0.5rem;
}
}

h1 {
margin-top: 0;
margin-bottom: 1rem;
}

.stages li {
margin-bottom: 1rem;
.stages {
margin: 0;

li {
margin-bottom: 1rem;
}
}

.stage-title {
Expand All @@ -46,6 +65,29 @@ h1 {
font-style: italic;
}

.selected-file {
margin-left: 0.5rem;
}

.help {
display: inline-block;
border: 1px solid #ccc;
background: #fafafa;
padding: 3px 5px;
border-radius: 4px;

summary {
cursor: pointer;
}

> div {
padding-top: 0.5rem;
display: flex;
flex-direction: column;
gap: 1rem;
}
}

#loading-cover {
width: 100vw;
height: 100vh;
Expand Down Expand Up @@ -95,10 +137,18 @@ button, label {
border: 1px solid #aaa;
border-radius: 4px;
padding: 3px 5px;
cursor: pointer;

&:hover {
background-color: #fafafa;

&:not([disabled]) {
cursor: pointer;

&:hover {
background-color: #fafafa;
}

&:active {
border-color: black;
background-color: white;
}
}
}

Expand All @@ -111,7 +161,49 @@ button, label {
display: flex;
flex-direction: column;
gap: 1rem;

table {
width: max-content;

td {
padding-bottom: 0.5rem;
}

td:first-child {
padding-right: 1rem;
}
}
}

.columns {
display: flex;
justify-content: space-between;
gap: 2rem;
}

/* .working-dir {
} */
.meta {
width: 200px;
border: 1px solid #ccc;
background-color: #fafafa;
padding: 0.5rem;
height: max-content;

h2 {
margin: 0 0 1rem;
}

> div {
display: flex;
flex-direction: column;
gap: 1rem;
}

pre {
max-width: 100%;
overflow-x: auto;
}

select {
max-width: 100%;
}
}
59 changes: 52 additions & 7 deletions src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fn git_output(f: impl FnOnce(&mut Command)) -> Result<String> {

pub struct GitRepo {}

const UPSTREAM: &str = "upstream";
pub const UPSTREAM: &str = "upstream";

impl GitRepo {
pub fn new() -> Self {
Expand All @@ -49,7 +49,7 @@ impl GitRepo {
git(|cmd| {
cmd.args(["clone", url]);
})
.context("Failed to clone")
.with_context(|| format!("Failed to clone: {url}"))
}

pub fn setup_upstream(&self, upstream: &GithubRepo) -> Result<()> {
Expand All @@ -66,26 +66,57 @@ impl GitRepo {
Ok(())
}

pub fn create_branch_from(&self, target_branch: &str, base_branch: &str) -> Result<()> {
pub fn create_branch_from(&self, target_branch: &str, base_branch: &str) -> Result<String> {
git(|cmd| {
cmd.args(["checkout", "-b", target_branch]);
})
.with_context(|| format!("Failed to checkout branch {target_branch}"))?;

git(|cmd| {
let res = git(|cmd| {
cmd.args([
"cherry-pick",
&format!("{UPSTREAM}/{base_branch}..{UPSTREAM}/{target_branch}"),
]);
})
.with_context(|| format!("Failed to cherry-pick commits onto {target_branch}"))?;
});

if res.is_err() {
tracing::warn!("Merge conflicts when cherry-picking, resorting to hard reset");

git(|cmd| {
cmd.args(["cherry-pick", "--abort"]);
})
.context("Failed to abort cherry-pick")?;

let upstream_target = format!("{UPSTREAM}/{target_branch}");
git(|cmd| {
cmd.args(["reset", "--hard", &upstream_target]);
})
.with_context(|| format!("Failed to hard reset to {upstream_target}"))?;

git(|cmd| {
cmd.args(["reset", "--soft", "main"]);
})
.context("Failed to soft reset to main")?;

git(|cmd| {
cmd.args(["commit", "-m", "Override with reference solution"]);
})
.context("Failed to commit reference solution")?;
}

git(|cmd| {
cmd.args(["push", "-u", "origin", target_branch]);
})
.with_context(|| format!("Failed to push branch {target_branch}"))?;

Ok(())
let head = self.head_commit()?;

git(|cmd| {
cmd.args(["checkout", "main"]);
})
.context("Failed to checkout main")?;

Ok(head)
}

pub fn checkout_main_and_pull(&self) -> Result<()> {
Expand All @@ -109,4 +140,18 @@ impl GitRepo {
.context("Failed to get head commit")?;
Ok(output.trim_end().to_string())
}

pub fn reset(&self, branch: &str) -> Result<()> {
git(|cmd| {
cmd.args(["reset", "--hard", branch]);
})
.context("Failed to reset")?;

git(|cmd| {
cmd.args(["push", "--force"]);
})
.context("Failed to push reset branch")?;

Ok(())
}
}
Loading

0 comments on commit e85ab23

Please sign in to comment.