Skip to content

Commit

Permalink
feat: git stage / unstage changes + fetch branches
Browse files Browse the repository at this point in the history
  • Loading branch information
NGPixel committed Feb 23, 2024
1 parent 77759fe commit 8ec4415
Show file tree
Hide file tree
Showing 8 changed files with 311 additions and 29 deletions.
7 changes: 6 additions & 1 deletion src-electron/electron-preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@ contextBridge.exposeInMainWorld('ipcBridge', {
ipcRenderer.on(channel, callback)
},

versions: process.versions,

promptSelectDirectory: (current, title) => ipcRenderer.invoke('promptSelectDirectory', { current, title }),
readDirectory: (dirPath) => ipcRenderer.invoke('readDirectory', { dirPath }),
fetchGitConfig: () => ipcRenderer.invoke('fetchGitConfig'),
clearGitKey: () => ipcRenderer.invoke('clearGitKey'),
gitCloneRepository: (url, target) => ipcRenderer.invoke('gitCloneRepository', { url, target }),
gitFetchOrigin: (dir) => ipcRenderer.invoke('gitFetchOrigin', { dir }),
gitListBranches: (dir) => ipcRenderer.invoke('gitListBranches', { dir }),
gitCommitsLog: (dir) => ipcRenderer.invoke('gitCommitsLog', { dir }),
gitStatusMatrix: (dir) => ipcRenderer.invoke('gitStatusMatrix', { dir })
gitStatusMatrix: (dir) => ipcRenderer.invoke('gitStatusMatrix', { dir }),
gitStageFiles: (dir, files) => ipcRenderer.invoke('gitStageFiles', { dir, files }),
gitUnstageFiles: (dir, files) => ipcRenderer.invoke('gitUnstageFiles', { dir, files })
})
81 changes: 81 additions & 0 deletions src-electron/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,33 @@ export default {
dir
})
},
/**
* List branches
*
* @param {Object} param0 Options
* @returns {Promise<Array>} List of branches
*/
async listBranches ({ dir }) {
const currentBranch = await git.currentBranch({
fs,
dir
})
const localBranches = await git.listBranches({
fs,
dir
})
const remoteBranches = await git.listBranches({
fs,
dir,
remote: 'origin'
})

return {
current: currentBranch,
local: localBranches,
remote: remoteBranches.filter(br => br !== 'HEAD')
}
},
/**
* Fetch commits history
*
Expand Down Expand Up @@ -198,6 +225,60 @@ export default {
}
}))
},
/**
* Stage Files
*
* @param {Object} param0 Options
* @returns {Promise<void>} Promise
*/
async stageFiles ({ dir, files }) {
const toAdd = files.filter(f => !f.isDeleted).map(f => f.path)
const toRemove = files.filter(f => f.isDeleted).map(f => f.path)
if (toAdd.length > 0) {
await git.add({
fs,
dir,
filepath: toAdd
})
}
if (toRemove.length > 0) {
for (const fl of toRemove) {
await git.remove({
fs,
dir,
filepath: fl
})
}
}
},
/**
* Unstage Files
*
* @param {Object} param0 Options
* @returns {Promise<void>} Promise
*/
async unstageFiles ({ dir, files }) {
const toUndelete = files.filter(f => f.isDeleted).map(f => f.path)
const toRemove = files.filter(f => !f.isDeleted).map(f => f.path)
if (toUndelete.length > 0) {
for (const fl of toUndelete) {
await git.resetIndex({
fs,
dir,
filepath: fl
})
}
}
if (toRemove.length > 0) {
for (const fl of toRemove) {
await git.remove({
fs,
dir,
filepath: fl
})
}
}
},
/**
* Authentication event handler
*
Expand Down
9 changes: 9 additions & 0 deletions src-electron/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,21 @@ export function registerCallbacks (mainWindow, mainMenu, git) {
ipcMain.handle('gitFetchOrigin', async (ev, opts) => {
return git.fetchOrigin({ dir: opts.dir })
})
ipcMain.handle('gitListBranches', async (ev, opts) => {
return git.listBranches({ dir: opts.dir })
})
ipcMain.handle('gitCommitsLog', async (ev, opts) => {
return git.commitsLog({ dir: opts.dir })
})
ipcMain.handle('gitStatusMatrix', async (ev, opts) => {
return git.statusMatrix({ dir: opts.dir })
})
ipcMain.handle('gitStageFiles', async (ev, opts) => {
return git.stageFiles({ dir: opts.dir, files: opts.files })
})
ipcMain.handle('gitUnstageFiles', async (ev, opts) => {
return git.unstageFiles({ dir: opts.dir, files: opts.files })
})
ipcMain.handle('gitCloneRepository', async (ev, opts) => {
return git.repoClone({
dir: opts.target,
Expand Down
Binary file added src/assets/draftforge-banner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 0 additions & 15 deletions src/assets/quasar-logo-vertical.svg

This file was deleted.

10 changes: 9 additions & 1 deletion src/components/AboutDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ q-dialog(ref='dialogRef', @hide='onDialogHide')
padding='xs'
@click='onDialogOK'
)
img(src='/images/draftforge-banner.png' alt="DraftForge")
img(src='../assets/draftforge-banner.png' alt="DraftForge")
q-card-section.bg-black
.text-caption App Version: #[strong {{ appVersion }}]
.text-caption Quasar Framework Version: #[strong {{ $q.version }}]
.text-caption Electron Version: #[strong {{ electronVersion }}]
.text-caption Chrome Version: #[strong {{ chromeVersion }}]
.text-caption Node.js Version: #[strong {{ nodeVersion }}]
.q-mt-md.text-amber-5
.text-caption Licensed under BSD 3-Clause
.text-caption Copyright © 2023-{{ currentYear }}, The IETF Trust
Expand All @@ -40,6 +43,11 @@ const { dialogRef, onDialogHide, onDialogOK } = useDialogPluginComponent()
// INFO
console.info(window.ipcBridge.versions)
const appVersion = process.env.APP_VERSION ?? 'Unknown'
const currentYear = new Date().getFullYear()
const chromeVersion = window.ipcBridge.versions.chrome
const electronVersion = window.ipcBridge.versions.electron
const nodeVersion = window.ipcBridge.versions.node
</script>
Loading

0 comments on commit 8ec4415

Please sign in to comment.