Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Working tree viz #122

Open
wants to merge 25 commits into
base: gh-pages
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
4d3d8bb
[WIP] Added Workspace Object
dpatel19 Mar 3, 2020
7085925
Got 3 boxes for Stash, CurrWs, and Index
dpatel19 Mar 4, 2020
329931d
Added basic blob rendering
dpatel19 Mar 28, 2020
a45f61a
Render stash and index as changesets
dpatel19 Mar 29, 2020
a413c38
Treat 'stash' as a stack
dpatel19 Mar 30, 2020
37db6ea
Added 'git stash drop'
dpatel19 Mar 30, 2020
1a2c79a
Added 'git stash drop' and remove Index blobs on commit
dpatel19 Mar 30, 2020
85ccd78
Clear Workspace and Index on 'git reset --hard'
dpatel19 Mar 30, 2020
7943d9f
Added expected behavior for 'git reset --soft' and '--mixed'
dpatel19 Mar 31, 2020
f808a15
Add working tree entry with 'edit' instead of 'git edit'
dpatel19 Mar 31, 2020
fc44756
Implemented 'git add <filename>'
dpatel19 Mar 31, 2020
bc5aa19
Implemented 'git checkout -- <filename>'
dpatel19 Apr 1, 2020
c6c0101
Cleaned up unstaging logic
dpatel19 Apr 4, 2020
089bde9
Fixed workspace to index bug
dpatel19 Apr 4, 2020
da23388
Added blob inflation
dpatel19 Apr 4, 2020
d38aaf9
Half height for history and workspace view
dpatel19 Apr 4, 2020
6a080cc
Removed unneeded code
dpatel19 Apr 4, 2020
aa76319
Cleaned up unused code
dpatel19 Apr 5, 2020
7a42a3d
Added padding between history and workspace view
dpatel19 Apr 5, 2020
d011d06
Implemented 'git stash apply'
dpatel19 Apr 8, 2020
b108a69
'git stash' default to '0'
dpatel19 Apr 18, 2020
89c1de1
Added example documentation
dpatel19 Apr 18, 2020
3de364e
Updated documentation to reflect new 'add' and 'stash' commands
dpatel19 Apr 18, 2020
c42a0e2
Removed debug prints
dpatel19 Apr 18, 2020
0baa509
Simplified renderBlobs() function
dpatel19 Apr 18, 2020
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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Type `help` in the command box to see a list of supported operations
`pres()` = Turn on presenter mode<br>
`undo` = Undo the last git command<br>
`redo` = Redo the last undone git command<br>
`edit` = Make a file edit<br>
`mode` = Change mode (`local` or `remote`)<br>
`clear` = Clear the history pane and reset the visualization

Expand All @@ -45,6 +46,8 @@ git reset
git rev_parse
git revert
git tag
git add
git stash
```


Expand Down
34 changes: 33 additions & 1 deletion css/explaingit.css
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,21 @@ span.cmd {
border: 1px dotted #AAA;
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 250px;
margin-left: 0;
height: 49%;
}

#ExplainGitZen-Container .ws-container {
display: inline-block;
border: 1px dotted #AAA;
position: absolute;
bottom: 0;
right: 0;
left: 250px;
margin-left: 5px;
height: 49%;
}

#ExplainGitZen-Container .svg-container.remote-container {
Expand Down Expand Up @@ -285,6 +296,27 @@ text.message-label {
font-size: 10px;
}

g.stash > rect {
fill: #FFCC66;
stroke: #CC9900;
stroke-width: 2;
}

g.curr-ws > rect {
fill: #7FC9FF;
stroke: #0026FF;
}

g.index > rect {
fill: #CCC;
stroke: #888;
}

g.blob-space > rect {
fill: #8ce08c;
stroke: #339900;
}

g.branch-tag > rect {
fill: #FFCC66;
stroke: #CC9900;
Expand Down
52 changes: 52 additions & 0 deletions examples/working_tree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
### Make local changes to the working tree

Simulate file edits with the 'edit' command. No filename is required.

```
edit
```

### The Stash

The stash a convenient place to store changes that aren't ready for committing.
To move these files changes to the stash:

```
git stash
```

To move these changes back to the working tree:

```
git stash apply
```
OR
```
git stash pop
```

Applying the changes will move the changes back to the working tree and leave a copy in the stash.
Popping the changes will move the changes back to the working tree but will remove the changes from
the stash.

### Add files to the index

If files are ready for committing, they can "staged"/"added to the index".

```
git add -u
```

The `-u` flag adds all previously tracked files to the staging area

### Remove files from the index

If a file needs to be removed from the staging area, use 'git reset'

```
git reset -- <filename>
```

### Committing

Committing files will remove them from the index and add them to the local repository.
6 changes: 3 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@
explainGit.reset();

var savedState = null
if (window.localStorage) {
savedState = JSON.parse(window.localStorage.getItem('git-viz-snapshot') || 'null')
}
//if (window.localStorage) {
// savedState = JSON.parse(window.localStorage.getItem('git-viz-snapshot') || 'null')
//}

var initial = Object.assign(copyDemo(lastDemo), {
name: 'Zen',
Expand Down
149 changes: 107 additions & 42 deletions js/controlbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ function(_yargs, d3, demos) {
function ControlBox(config) {
this.historyView = config.historyView;
this.originView = config.originView;
this.workspace = config.workspace;
this.initialMessage = config.initialMessage || 'Enter git commands below.';
this._commandHistory = [];
this._currentCommand = -1;
Expand Down Expand Up @@ -85,7 +86,6 @@ function(_yargs, d3, demos) {
},

changeMode: function (mode) {
console.log(mode)
if (mode === 'local' && this.historyView) {
this.mode = 'local'
} else if (mode === 'remote' && this.originView) {
Expand Down Expand Up @@ -231,6 +231,7 @@ function(_yargs, d3, demos) {
this.info('pres() = Turn on presenter mode')
this.info('undo = Undo the last git command')
this.info('redo = Redo the last undone git command')
this.info('edit = Make a file edit')
this.info('mode = Change mode (`local` or `remote`)')
this.info('clear = Clear the history pane and reset the visualization')
this.info()
Expand All @@ -250,6 +251,8 @@ function(_yargs, d3, demos) {
this.info('`git rev_parse`')
this.info('`git revert`')
this.info('`git tag`')
this.info('`git add`')
this.info('`git stash`')
return
}

Expand Down Expand Up @@ -300,6 +303,12 @@ function(_yargs, d3, demos) {
return
}

if (entry.toLowerCase() === 'edit') {
var workspace = this.workspace;
workspace.addBlob(null, workspace.curr_ws);
return
}

if (entry.toLowerCase() === 'clear') {
window.resetVis()
return
Expand Down Expand Up @@ -378,6 +387,7 @@ function(_yargs, d3, demos) {
this.getRepoView().amendCommit(opts.m || this.getRepoView().getCommit('head').message)
} else {
this.getRepoView().commit(null, opts.m);
workspace.removeAllBlobs(workspace.index);
}
}, function(before, after) {
var reflogMsg = 'commit: ' + msg
Expand Down Expand Up @@ -472,25 +482,33 @@ function(_yargs, d3, demos) {
},

checkout: function(args, opts) {
if (opts.b) {
if (opts._[0]) {
this.branch(null, null, opts.b + ' ' + opts._[0])
} else {
this.branch(null, null, opts.b)
if (args && args[0] === "--") {
args.shift();
while (args.length > 0) {
var arg = args.shift();
workspace.moveBlobByName(workspace.curr_ws, undefined, arg);
}
} else {
if (opts.b) {
if (opts._[0]) {
this.branch(null, null, opts.b + ' ' + opts._[0])
} else {
this.branch(null, null, opts.b)
}
}
}

var name = opts.b || opts._[0]
var name = opts.b || opts._[0]

this.transact(function() {
this.getRepoView().checkout(name);
}, function(before, after) {
this.getRepoView().addReflogEntry(
'HEAD', after.commit.id,
'checkout: moving from ' + before.ref +
' to ' + name
)
})
this.transact(function() {
this.getRepoView().checkout(name);
}, function(before, after) {
this.getRepoView().addReflogEntry(
'HEAD', after.commit.id,
'checkout: moving from ' + before.ref +
' to ' + name
)
})
}
},

tag: function(args) {
Expand Down Expand Up @@ -534,33 +552,38 @@ function(_yargs, d3, demos) {
},

reset: function(args) {
var unstage = false;
while (args.length > 0) {
var arg = args.shift();

switch (arg) {
case '--soft':
this.info(
'The "--soft" flag works in real git, but ' +
'I am unable to show you how it works in this demo. ' +
'So I am just going to show you what "--hard" looks like instead.'
);
break;
case '--mixed':
this.info(
'The "--mixed" flag works in real git, but ' +
'I am unable to show you how it works in this demo. ' +
'So I am just going to show you what "--hard" looks like instead.'
);
break;
case '--hard':
this.doReset(args.join(' '));
args.length = 0;
break;
default:
var remainingArgs = [arg].concat(args);
args.length = 0;
this.info('Assuming "--hard".');
this.doReset(remainingArgs.join(' '));
if (unstage) {
workspace.moveBlobByName(workspace.index, workspace.curr_ws, arg);
} else {
switch (arg) {
case '--soft':
// no resetting of the index or working tree
this.doReset(args.join(' '));
args.length = 0;
break;
case '--mixed':
// reset just the index
this.doReset(args.join(' '));
workspace.removeAllBlobs(workspace.index);
args.length = 0;
break;
case '--hard':
this.doReset(args.join(' '));
// reset the index and the working tree
workspace.removeAllBlobs(workspace.curr_ws);
workspace.removeAllBlobs(workspace.index);
args.length = 0;
break;
case "HEAD":
// unstage the file (move from index to working tree)
unstage = true;
break;
default:
this.info("Invalid ref: " + arg);
}
}
}
},
Expand Down Expand Up @@ -915,6 +938,48 @@ function(_yargs, d3, demos) {
this.info("Real git reflog supports the '" + subcommand +
"' subcommand but this tool only supports 'show' and 'exists'")
}
},

add: function(args) {
// Create boxes to visualize working tree, index, stash
var workspace = this.workspace;
while (args.length > 0) {
var arg = args.shift();
switch (arg) {
case '-u':
case '.':
workspace.addBlob(workspace.curr_ws, workspace.index, true);
break;
default:
workspace.moveBlobByName(workspace.curr_ws, workspace.index, arg);
break;
}
}
return;
},

stash: function(args) {
// Create boxes to visualize working tree, index, stash
var workspace = this.workspace;
var stash_id = "0";
if (args && args[0] === "pop") {
workspace.addBlob(workspace.stash, workspace.curr_ws);
} else if (args && args[0] === "apply") {
if (args[1] != undefined) {
stash_id = args[1];
}
workspace.moveBlobByName(workspace.stash, workspace.curr_ws, stash_id, false);
} else if (args && args[0] === "drop") {
if (args[1] != undefined) {
stash_id = args[1];
}
workspace.removeBlob(workspace.stash, stash_id);
} else if (args && args[0] === "clear") {
workspace.removeAllBlobs(workspace.stash);
} else {
workspace.addBlob(workspace.curr_ws, workspace.stash, true);
}
return;
}
};

Expand Down
Loading