Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

RFC: Concept of marking a workspace as dirty#9477

MrPeacockNLB started this conversation inRFCs
Discussion options

Description

We are using ephemeral workspaces and open for each and every task a new workspace. If one is working on multiple projects simultaneously the list can get easely longer. Each workspace is derived from a repository as everybody nowadays works with aCVS like git. I often open a repository for read only in coder. So there were workspaces with no changes in it. So far so good. But it would be nice if one can see if there is unsaved work before deleting a workspace.

Currently one has to open the workspace and do some manual checking if there were some unsaved change in it. This is a time wasting task. Deleting a workspace means always the anwsering the security dialog or closing the workspace with the coder binary.

Solution

If there is some unsaved work in the workspace then this workspace is marked asdirty in the UI. This should be periodly requested from the coder daemon like metadata values. If the executed code return a code 0 then the workspace is clean or something like that. The executed code can check if there is some unsaved work in the filesystem in the workspace.

If a workspace is marked as clean a simple delete should remove a workspace without any dialog. There should also be the ability to cleanup all clean workspaces at once.

Deleting a dirty workspace should raise the known security dialog to prevent accidentally deleting unsaved work.

You must be logged in to vote

Replies: 1 comment 5 replies

Comment options

I've been playing around a bit and implemented a very simple POC for this. I put some Bash scripts into a metadata resource to get current status of opened workspace.

image

image

image

metadata {    display_name = "Workspace status"    key          = "dirty"    script = <<EOT      # jump into standard dir      cd /workspace/workdir      # check uncommitted changes      DIFF=$(git diff --exit-code)      if [[ $? -gt 0 ]]; then          echo "uncommitted changes"          exit 1      fi      # check for untracked files      if output=$(git status --porcelain) && [ -z "$output" ]; then        echo "workspace is clean"      else        echo "untracked files"        exit 1      fi    EOT    interval = 10    timeout = 5  }

PS: Code is far from perfect!

You must be logged in to vote
5 replies
@matifali
Comment options

This is a good POC. Something to add to my personal templates. Thanks.

@michaelbrewer
Comment options

Awesome idea, i think having a script that can take the WORKSPACE_DIR (which might not be the same as the HOME dir), and then check for any folder that might be repos. Before doing the checks ie:

WORKSPACE_DIR=/projects has proj1, proj2, and proj3 checked out.

@michaelbrewer
Comment options

The next part which would be nice is to allow users to "Delete" workspaces which are clean via a filter on the "metadata"

@michaelbrewer
Comment options

You can also detect if changes have not been pushed yet.

if output=$(git status --porcelain)&& [-z"$output" ];thenif git log --branches --not --remotes| grep.> /dev/null;thenecho"changes not pushed"exit 1elseecho"workspace is clean"fielseecho"untracked files"exit 1fi
@michaelbrewer
Comment options

A more complete snippet. This also handles remote changes.

metadata {display_name="Workspace status"key="7_dirty"script=<<EOT      if [ -z "${local.git_url}" ]; then        echo "not a git repo"        exit 0      fi      cd${local.workspace_home}/${local.folder_name}      DIFF=$(git diff --exit-code)      if [[ $? -gt 0 ]]; then        echo "uncommitted changes"        exit 1      fi      if output=$(git status --porcelain) && [ -n "$output" ]; then        echo "untracked files"        exit 1      fi      if git log --branches --not --remotes | grep . > /dev/null; then        echo "changes not pushed"        exit 1      fi      BNAME=$(git rev-parse --abbrev-ref HEAD)      git fetch -q origin $BNAME || {        echo "workspace is clean"        exit 0      }      LOCAL=$(git rev-parse @)      REMOTE=$(git rev-parse @{u})      BASE=$(git merge-base @ @{u})      if [ $LOCAL = $REMOTE ]; then        echo "workspace is clean"      elif [ $LOCAL = $BASE ]; then        echo "needs to pull changes"        exit 1      else        echo "workspace has diverged"        exit 1      fi    EOTinterval=10timeout=5  }
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
RFCs
Labels
None yet
3 participants
@MrPeacockNLB@michaelbrewer@matifali
Converted from issue

This discussion was converted from issue #8962 on September 01, 2023 06:47.


[8]ページ先頭

©2009-2025 Movatter.jp