Skip to content

Commit

Permalink
Add ability to use git branch -d.
Browse files Browse the repository at this point in the history
  • Loading branch information
Wei Wang committed Mar 25, 2013
1 parent 5804dd4 commit 6eb3733
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
40 changes: 40 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ <h4>&nbsp;</h4>
<div class="twocol">
<h4>Undo/Delete</h4>
<a id="open-reset" class="openswitch" href="#">git reset</a>
<a id="open-branch-d" class="openswitch" href="#">git branch -d</a>
</div>
<div class="twocol">
<h4>Combine Branches</h4>
Expand Down Expand Up @@ -123,6 +124,14 @@ <h4>Interacting with Remote Server</h4>
the command <span class="cmd">git clean -df</span>.
</p>
</div>
<div id="ExplainGitBranch-d-Container" class="twelvecol concept-container">
<p>
<span class="cmd">git branch -d</span> is used to delete branches.
I have pre-created a bunch of branches for you to delete in the playground below.
Have at it.
</p>
</div>
</div>
<div id="ExplainGitMerge-Container" class="twelvecol concept-container">
<p>
<span class="cmd">git merge</span> will create a new commit with two parents. The resulting
Expand Down Expand Up @@ -253,6 +262,37 @@ <h4>Interacting with Remote Server</h4>
});
</script>

<script type="text/javascript">
require(['explaingit'], function (explainGit) {
var openSwitch = document.getElementById('open-branch-d'),
open;

open = function () {
explainGit.reset();

explainGit.open({
name: 'Branch-d',
height: 500,
commitData: [
{id: '98ca9b5', tags: ['origin/master']},
{id: '77oa0ph', parent: '98ca9b5'},
{id: 'cj5mlg3', parent: '77oa0ph', tags: ['master']},
{id: '4gc3uuf', parent: '98ca9b5', tags: ['protoss']},
{id: 'def6ayi', parent: '77oa0ph'},
{id: 'amcqj4r', parent: 'def6ayi', tags: ['zerg']},
{id: 'a21i3m6', parent: '77oa0ph'},
{id: 'y73kv3k', parent: 'a21i3m6', tags: ['terran']}
],
currentBranch: 'terran',
initialMessage:
'Delete some branches.'
});
};

openSwitch.addEventListener('click', open, false);
});
</script>

<script type="text/javascript">
require(['explaingit'], function (explainGit) {
var openSwitch = document.getElementById('open-merge'),
Expand Down
4 changes: 4 additions & 0 deletions js/controlbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ define(['d3'], function () {
);
args.length = 0;
break;
case '-d':
var name = args.pop();
this.historyView.deleteBranch(name);
break;
default:
var remainingArgs = [arg].concat(args);
args.length = 0;
Expand Down
31 changes: 31 additions & 0 deletions js/historyview.js
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,8 @@ define(['d3'], function () {
existingTags = this.svg.selectAll('g.branch-tag')
.data(tagData, function (d) { return d.name; });

existingTags.exit().remove();

existingTags.select('rect')
.transition()
.duration(500)
Expand Down Expand Up @@ -737,6 +739,35 @@ define(['d3'], function () {
return this;
},

deleteBranch: function (name) {
var branchIndex,
commit;

if (!name || name.trim() === '') {
throw new Error('You need to give a branch name.');
}

if (name === this.currentBranch) {
throw new Error('Cannot delete the currently checked-out branch.');
}

branchIndex = this.branches.indexOf(name);

if (branchIndex === -1) {
throw new Error('That branch doesn\'t exist.');
}

this.branches.splice(branchIndex, 1);
commit = this.getCommit(name);
branchIndex = commit.tags.indexOf(name);

if (branchIndex > -1) {
commit.tags.splice(branchIndex, 1);
}

this._renderTags();
},

checkout: function (ref) {
var commit = this.getCommit(ref);

Expand Down

0 comments on commit 6eb3733

Please sign in to comment.