Skip to content
This repository was archived by the owner on Aug 15, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ This extension depends on [Code for IBM i](https://github.com/halcyon-tech/code-

This adds 'Status', 'Commits' and 'File History' to the source control view. It will assume that your home directory, set in Code for IBM i is also a git repository. When you change your home directory, the panels will refresh automatically.

#### Status
TODO: Stashing

#### Branches

This view will allow you to stage, unstage, restore and view a diff of your working tree.
This view will display remote and local branches and allow you to create, delete, checkout, and merge branches.

To do:
#### Status

* Commit, pull & push
This view will allow you to commit, pull, push, stage, unstage, restore and view a diff of your working tree.

#### Commits

Expand Down
6 changes: 6 additions & 0 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const vscode = require(`vscode`);

const {instance, Field, CustomUI} = vscode.extensions.getExtension(`halcyontechltd.code-for-ibmi`).exports;

const branchesView = require(`./src/views/branches`);
const statusView = require(`./src/views/status`);
const commitView = require(`./src/views/commits`);
const fileHistory = require(`./src/views/fileHistory`);
Expand All @@ -19,6 +20,11 @@ function activate(context) {
console.log(`Congratulations, your extension "git-client-ibmi" is now active!`);

context.subscriptions.push(
vscode.window.registerTreeDataProvider(
`git-client-ibmi.branches`,
new branchesView(context)
),

vscode.window.registerTreeDataProvider(
`git-client-ibmi.status`,
new statusView(context)
Expand Down
63 changes: 61 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@
"onCommand:git-client-ibmi.commits.refresh",
"onView:git-client-ibmi.fileHistory",
"onCommand:git-client-ibmi.viewCommitFile",
"onCommand:git-client-ibmi.viewCommitFileDiff"
"onCommand:git-client-ibmi.viewCommitFileDiff",
"onCommand:git-client-ibmi.branches.refresh",
"onCommand:git-client-ibmi.branches.branch",
"onCommand:git-client-ibmi.branches.deleteBranch",
"onCommand:git-client-ibmi.branches.checkout",
"onCommand:git-client-ibmi.branches.merge"
],
"main": "./extension",
"contributes": {
Expand Down Expand Up @@ -104,6 +109,33 @@
"command": "git-client-ibmi.viewCommitFileDiff",
"title": "View diff",
"category": "Git on IBM i"
},
{
"command": "git-client-ibmi.branches.branch",
"title": "Create Branch",
"category": "Git on IBM i",
"icon": "$(git-branch-create)"
},
{
"command": "git-client-ibmi.branches.deleteBranch",
"title": "Delete Branch",
"category": "Git on IBM i"
},
{
"command": "git-client-ibmi.branches.checkout",
"title": "Checkout Branch",
"category": "Git on IBM i"
},
{
"command": "git-client-ibmi.branches.merge",
"title": "Merge Branch",
"category": "Git on IBM i"
},
{
"command": "git-client-ibmi.branches.refresh",
"title": "Refresh branches view",
"category": "Git on IBM i",
"icon": "$(refresh)"
}
],
"viewsWelcome": [{
Expand All @@ -113,6 +145,11 @@
}],
"views": {
"scm": [{
"id": "git-client-ibmi.branches",
"name": "Branches",
"contextualTitle": "IBM i"
},
{
"id": "git-client-ibmi.status",
"name": "Status",
"contextualTitle": "IBM i"
Expand Down Expand Up @@ -156,6 +193,16 @@
"command": "git-client-ibmi.commits.refresh",
"group": "navigation",
"when": "view == git-client-ibmi.commits"
},
{
"command": "git-client-ibmi.branches.branch",
"group": "navigation",
"when": "view == git-client-ibmi.branches"
},
{
"command": "git-client-ibmi.branches.refresh",
"group": "navigation",
"when": "view == git-client-ibmi.branches"
}
],
"view/item/context": [
Expand All @@ -174,6 +221,18 @@
{
"command": "git-client-ibmi.viewCommitFile",
"when": "view == git-client-ibmi.commits && viewItem == commitFile"
},
{
"command": "git-client-ibmi.branches.checkout",
"when": "view == git-client-ibmi.branches && viewItem == remote || viewItem == local"
},
{
"command": "git-client-ibmi.branches.deleteBranch",
"when": "view == git-client-ibmi.branches && viewItem == remote || viewItem == local"
},
{
"command": "git-client-ibmi.branches.merge",
"when": "view == git-client-ibmi.branches && viewItem == local"
}
]
}
Expand All @@ -195,4 +254,4 @@
"mocha": "^8.2.1",
"vscode-test": "^1.5.0"
}
}
}
106 changes: 105 additions & 1 deletion src/api/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,4 +219,108 @@ module.exports = class Git {
this.path,
);
}
}

/**
* @returns {remote: branch_name[], local: {branch_name, state}[]}}
*/
async list_branches() {
const connection = instance.getConnection();
let remote = [], local = [];

let item = {branch_name: '', state: ''};
let content = await connection.paseCommand(
`echo '"' && ${this.gitPath} branch --all --list`,
this.path,
);

content = content.substring(1);

for (let line of content.split(`\n`)) {
if (line.trim() === ``) continue;

item.state = (line[0] == '*') ? 'checked out' : '';
item.branch_name = line.substr(2);
const remote_or_local = (item.branch_name.split('/')[0] == 'remotes') ? 'remote' : 'local';

switch (remote_or_local) {
case `remote`:
remote.push(item.branch_name);
break;
case `local`:
local.push({branch_name: item.branch_name, state: item.state});
break;
}
}

return {remote, local};
}

/**
* Create a branch
* @param {string} new_branch_name
*/
async create_branch(new_branch_name) {
const connection = instance.getConnection();
await connection.paseCommand(
`${this.gitPath} branch "${new_branch_name}"`,
this.path,
);
}

/**
* Delete a remote branch
* @param {string} branch_to_delete
* @param {string} remote_or_local
*/
async deleteBranch(branch_to_delete, remote_or_local) {
let result = await vscode.window.showWarningMessage(`Are you sure you want to delete branch ${branch_to_delete}?`, `Yes`, `Cancel`);

if (result === `Yes`) {
const connection = instance.getConnection();
if(remote_or_local == "remote"){
const split_branch_to_delete = branch_to_delete.split('/');
var command = `${this.gitPath} push "${split_branch_to_delete[1]}" --delete "${split_branch_to_delete[2]}"`;
}
else{
var command = `${this.gitPath} branch -D "${branch_to_delete}"`;
}

await connection.paseCommand(
command,
this.path,
);
}
}

/**
* Checkout a branch
* @param {string} branch_to_checkout
* @param {string} remote_or_local
*/
async checkout(branch_to_checkout, remote_or_local) {
const connection = instance.getConnection();
if(remote_or_local == "remote"){
const split_branch_name = branch_to_checkout.split('/');
var command = `${this.gitPath} checkout -b "${split_branch_name[2]}" "${split_branch_name[1]}"/"${split_branch_name[2]}"`;
}
else{
var command = `${this.gitPath} checkout "${branch_to_checkout}"`;
}
await connection.paseCommand(
command,
this.path,
);
}

/**
* Merge a branch into the current branch
* @param {string} branch_to_merge_into_current_branch
*/
async merge(branch_to_merge_into_current_branch) {
const connection = instance.getConnection();
await connection.paseCommand(
`${this.gitPath} merge "${branch_to_merge_into_current_branch}"`,
this.path,
);
}
}
Loading