- Notifications
You must be signed in to change notification settings - Fork924
RFC: Concept of marking a workspace as dirty#9477
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
DescriptionWe 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. SolutionIf 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. |
BetaWas this translation helpful?Give feedback.
All reactions
❤️ 1👀 3
Replies: 1 comment 5 replies
-
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.
PS: Code is far from perfect! |
BetaWas this translation helpful?Give feedback.
All reactions
👍 2
-
This is a good POC. Something to add to my personal templates. Thanks. |
BetaWas this translation helpful?Give feedback.
All reactions
👍 1
-
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. |
BetaWas this translation helpful?Give feedback.
All reactions
-
The next part which would be nice is to allow users to "Delete" workspaces which are clean via a filter on the "metadata" |
BetaWas this translation helpful?Give feedback.
All reactions
-
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 |
BetaWas this translation helpful?Give feedback.
All reactions
🎉 1
-
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 } |
BetaWas this translation helpful?Give feedback.
All reactions
This discussion was converted from issue #8962 on September 01, 2023 06:47.