Skip to content

Commit

Permalink
Add warning when local repo is out of date (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
willcrichton authored Dec 17, 2024
1 parent b6ded66 commit 71d933d
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 16 deletions.
14 changes: 0 additions & 14 deletions .github/workflows/pre-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,7 @@ jobs:
with:
targets: ${{ matrix.target }}

- name: Install Node (Windows)
if: matrix.os == 'windows-latest'
uses: actions/setup-node@v4
with:
node-version: 20

- name: Install pnpm (Windows)
if: matrix.os == 'windows-latest'
uses: pnpm/action-setup@v4
with:
version: 9.9

- uses: tauri-apps/tauri-action@v0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
args: --target ${{ matrix.target }}
projectPath: rs/crates/repo-quest
Expand Down
6 changes: 6 additions & 0 deletions js/packages/repo-quest/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,12 @@ let QuestView: React.FC<{
<div className="quest-dir">
<strong>Quest directory:</strong> <code>{state.dir}</code>
</div>
{state.behind_origin && (
<div className="behind-origin-warning">
Your local repo is not up-to-date with the Github repo, run{" "}
<code>git pull</code>!
</div>
)}
<ol className="stages" start={0}>
{_.range(cur_stage + 1).map(i => (
<StageView
Expand Down
7 changes: 7 additions & 0 deletions js/packages/repo-quest/styles/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -257,4 +257,11 @@ dialog {
position: absolute;
top: 2rem;
right: 1rem;
}

.behind-origin-warning {
font-weight: bold;
padding: 0.5rem;
margin: 1rem 0;
background-color: rgb(255, 251, 167);
}
15 changes: 14 additions & 1 deletion rs/crates/rq-core/src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,14 @@ impl GitRepo {
pub fn setup_upstream(&self, upstream: &GithubRepo) -> Result<()> {
let remote = upstream.remote(GitProtocol::Https);
git!(self, "remote add {UPSTREAM} {remote}")?;
git!(self, "fetch {UPSTREAM}")?;
self.fetch(UPSTREAM)?;
Ok(())
}

pub fn fetch(&self, remote: &str) -> Result<()> {
git!(self, "fetch {remote}")
}

pub fn upstream(&self) -> Result<Option<&'static str>> {
let status = command(&format!("git remote get-url {UPSTREAM}"), &self.path)
.status()
Expand Down Expand Up @@ -240,6 +244,15 @@ impl GitRepo {
.collect()
}

pub fn is_behind_origin(&self) -> Result<bool> {
let out = git_output!(self, "rev-list --count main..origin/main")?;
let count = out
.trim()
.parse::<i32>()
.with_context(|| format!("rev-list returned non-numeric output:\n{out}"))?;
Ok(count > 0)
}

pub fn write_initial_files(&self, package: &QuestPackage) -> Result<()> {
for (rel_path, contents) in &package.initial {
let abs_path = self.path.join(rel_path);
Expand Down
4 changes: 3 additions & 1 deletion rs/crates/rq-core/src/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ impl GithubRepo {
let user = load_user().await.context("Failed to load user")?;
let params = json!({
"name": &package.config.repo,
"private": true,
});
octocrab::instance()
.post::<_, serde_json::Value>("/user/repos", Some(&params))
Expand Down Expand Up @@ -304,7 +305,8 @@ impl GithubRepo {
.repo_handler()
.generate(name)
.owner(&user)
.private(true)
// TODO: make this configurable? Right now we don't want privacy so we can see learner progress
// .private(true)
.send()
.await
.with_context(|| format!("Failed to clone template repo {}/{}", base.user, base.name))?;
Expand Down
4 changes: 4 additions & 0 deletions rs/crates/rq-core/src/quest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ pub struct StateDescriptor {
stages: Vec<StageState>,
state: QuestState,
can_skip: bool,
behind_origin: bool,
}

pub enum CreateSource {
Expand Down Expand Up @@ -334,15 +335,18 @@ impl Quest {

pub async fn state_descriptor(&self) -> Result<StateDescriptor> {
let state = self.infer_state().await?;
let behind_origin = self.origin_git.is_behind_origin()?;
Ok(StateDescriptor {
dir: self.dir.clone(),
stages: self.stage_states(),
state,
can_skip: self.template.can_skip(),
behind_origin,
})
}

pub async fn infer_state_update(&self) -> Result<()> {
self.origin_git.fetch("origin")?;
self.origin.fetch().await?;
let state = self.state_descriptor().await?;
self.state_event.emit(state)?;
Expand Down

0 comments on commit 71d933d

Please sign in to comment.