Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
gkalpak committed Jul 4, 2024
1 parent e2813a6 commit 6630760
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 25 deletions.
35 changes: 20 additions & 15 deletions lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ const PR_REMOTE_ALIAS_PREFIX = 'gcoghpr';
const PR_LOCAL_BRANCH_PREFIX = 'gcoghpr';

const SOURCE_NVM_CMD = '. $NVM_DIR/nvm.sh';
const GIT_GET_DEFAULT_BRANCH_CMD =
`${['master', 'main'].map(b => `(git show-ref --heads --quiet ${b} && echo ${b})`).join(' || ')} || ` +
'echo unknown-branch';
const GLOBAL_NPM_PACKAGES = [
'@angular/cli',
'@gkalpak/aliases',
Expand All @@ -39,7 +36,7 @@ const GLOBAL_NPM_PACKAGES = [

const DESC_REPLACEMENTS = {
[AliasUnknown.DESCRIPTION]: '???',
[`::${GIT_GET_DEFAULT_BRANCH_CMD}`]: '<default-branch>',
'::gdefb': '<default-branch>',
'::__a-builds-dir': '(<.../angular/aio/aio-builds-setup>)',
'::__g-pick-branch --gkcu-returnOutput=1': '(interactively pick a branch)',
'::__g-pick-commit --gkcu-returnOutput=1': '(interactively pick a commit)',
Expand Down Expand Up @@ -242,7 +239,17 @@ const ALIASES = {
git: {
// STATUS
gs: new AliasDefault('git status $*'),
gdefb: new AliasDefault(GIT_GET_DEFAULT_BRANCH_CMD),
gdefb: new AliasDefault(
'node --print "' +
'const rem = \'origin\'; ' +
'const exec = cmd => child_process.execSync(cmd, {encoding: \'utf8\', stdio: \'pipe\'}); ' +
'try { ' +
'exec(`git rev-parse --abbrev-ref ${rem}/HEAD`).slice(rem.length + 1); ' +
'} catch { ' +
'exec(' +
'`${[\'main\', \'master\'].map(b => `(git show-ref --heads --quiet ${b} && echo ${b})`).join(\' || \')}' +
' || echo unknown-branch`); ' +
'}"'),
gl: new AliasDefault('git log --decorate $* || true'),
gl1: new AliasDefault('git log --decorate --oneline $* || true'),
gl1g: new AliasDefault('git log --decorate --oneline | grep $*'),
Expand All @@ -264,7 +271,7 @@ const ALIASES = {

// CHECKOUT
gco: new AliasDefault('git checkout ${*:::__g-pick-branch --gkcu-returnOutput=1}'),
gcom: new AliasDefault(`git checkout \${0:::${GIT_GET_DEFAULT_BRANCH_CMD}} $*`),
gcod: new AliasDefault('git checkout ${0:::gdefb} $*'),
gcopr: new AliasDefault('git fetch upstream pull/$1/head && git checkout FETCH_HEAD'),
gcoghpr: SCRIPT_BACKED_ALIAS('gcoghpr', 'Check out a GitHub pull request as a local branch.'),
'gcoghpr-cleanup': new AliasDefault(
Expand Down Expand Up @@ -300,32 +307,30 @@ const ALIASES = {
// BRANCH
gb: new AliasDefault('git branch $*'),
gbc: new AliasDefault(GIT_CREATE_BRANCH_CMD('${2:HEAD}')),
gbcm: new AliasDefault(GIT_CREATE_BRANCH_CMD(`\${0:::${GIT_GET_DEFAULT_BRANCH_CMD}}`)),
gbcd: new AliasDefault(GIT_CREATE_BRANCH_CMD('${0:::gdefb}')),
gbco: new AliasDefault(`git fetch origin $1 && ${GIT_CREATE_BRANCH_CMD('origin/$1')}`),
gbd: new AliasDefault('git branch --delete --force ${*:::__g-pick-branch --gkcu-returnOutput=1}'),

// PULL(-REBASE)
gpr: new AliasDefault('git pull --rebase $*'),
gpro: new AliasDefault('git pull --rebase origin ${*:::git rev-parse --abbrev-ref HEAD}'),
gprom: new AliasDefault(`git pull --rebase origin \${0:::${GIT_GET_DEFAULT_BRANCH_CMD}} $*`),
gprod: new AliasDefault('git pull --rebase origin ${0:::gdefb} $*'),
gpru: new AliasDefault('git pull --rebase upstream ${*:::git rev-parse --abbrev-ref HEAD}'),
gprum: new AliasDefault(`git pull --rebase upstream \${0:::${GIT_GET_DEFAULT_BRANCH_CMD}} $*`),
gprud: new AliasDefault('git pull --rebase upstream ${0:::gdefb} $*'),

// SYNC DEFAULT BRANCH
gsync: new AliasDefault(
`git checkout \${1:::${GIT_GET_DEFAULT_BRANCH_CMD}} && ` +
`git pull upstream \${1:::${GIT_GET_DEFAULT_BRANCH_CMD}} && ` +
`git push origin \${1:::${GIT_GET_DEFAULT_BRANCH_CMD}}`),
'git checkout ${1:::gdefb} && git pull upstream ${1:::gdefb} && git push origin ${1:::gdefb}'),


// REBASE
grb: new AliasDefault('git rebase ${*:::__g-pick-branch --gkcu-returnOutput=1}'),
grbm: new AliasDefault(`git rebase --ignore-date \${0:::${GIT_GET_DEFAULT_BRANCH_CMD}} $*`),
grba: new AliasDefault('git rebase --abort'),
grbc: new AliasDefault('git rebase --continue'),
grbd: new AliasDefault('git rebase --ignore-date ${0:::gdefb} $*'),
grbi: new AliasDefault('git rebase --interactive HEAD~$1'),
grbia: new AliasDefault('git rebase --autosquash --interactive HEAD~$1'),
grbin: new AliasDefault('git rebase --no-autosquash --interactive HEAD~$1'),
grbc: new AliasDefault('git rebase --continue'),
grba: new AliasDefault('git rebase --abort'),
gmt: new AliasDefault('git mergetool'),
gcl: new AliasDefault('git clean --interactive "${0:::git rev-parse --show-toplevel}"'),

Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"gaa": "./bin/git/gaa.js",
"gb": "./bin/git/gb.js",
"gbc": "./bin/git/gbc.js",
"gbcm": "./bin/git/gbcm.js",
"gbcd": "./bin/git/gbcd.js",
"gbco": "./bin/git/gbco.js",
"gbd": "./bin/git/gbd.js",
"gcl": "./bin/git/gcl.js",
Expand All @@ -71,9 +71,9 @@
"gcmifc": "./bin/git/gcmifc.js",
"gcmifs": "./bin/git/gcmifs.js",
"gco": "./bin/git/gco.js",
"gcod": "./bin/git/gcod.js",
"gcoghpr": "./bin/git/gcoghpr.js",
"gcoghpr-cleanup": "./bin/git/gcoghpr-cleanup.js",
"gcom": "./bin/git/gcom.js",
"gcopr": "./bin/git/gcopr.js",
"gcp": "./bin/git/gcp.js",
"gcpa": "./bin/git/gcpa.js",
Expand All @@ -98,16 +98,16 @@
"gpf": "./bin/git/gpf.js",
"gpr": "./bin/git/gpr.js",
"gpro": "./bin/git/gpro.js",
"gprom": "./bin/git/gprom.js",
"gprod": "./bin/git/gprod.js",
"gpru": "./bin/git/gpru.js",
"gprum": "./bin/git/gprum.js",
"gprud": "./bin/git/gprud.js",
"grb": "./bin/git/grb.js",
"grba": "./bin/git/grba.js",
"grbc": "./bin/git/grbc.js",
"grbd": "./bin/git/grbd.js",
"grbi": "./bin/git/grbi.js",
"grbia": "./bin/git/grbia.js",
"grbin": "./bin/git/grbin.js",
"grbm": "./bin/git/grbm.js",
"grs": "./bin/git/grs.js",
"grs1": "./bin/git/grs1.js",
"gs": "./bin/git/gs.js",
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/git.bin.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe(SCRIPT_DIR, () => {
beforeAll(async () => {
// If this test run is on CI for a tag, then the branch refs may not be available.
// NOTE: This may also affect non-master/main branches, but these are currently not used.
isOnCiTag = Boolean(process.env.CI) &&
isOnCiTag = false && Boolean(process.env.CI) &&
/^v\d+\.\d+\.\d+$/.test(await testingUtils.testCmd('git describe --tags || true')) &&
/^$/.test(await testingUtils.testCmd('git show-ref --heads || true'));
});
Expand Down
6 changes: 2 additions & 4 deletions test/unit/alias-scripts/gcoghpr.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import chalk from 'chalk';
import stripAnsi from 'strip-ansi';

import {_testing, Gcoghpr, main} from '../../../lib/alias-scripts/gcoghpr.js';
import {PR_LOCAL_BRANCH_PREFIX, PR_REMOTE_ALIAS_PREFIX} from '../../../lib/constants.js';
import {ALIASES, PR_LOCAL_BRANCH_PREFIX, PR_REMOTE_ALIAS_PREFIX} from '../../../lib/constants.js';
import {loadPackageJson} from '../../test-utils.js';

import {MockExecutor, MockHttps, MockLogger} from './gcoghpr.mocks.js';
Expand All @@ -21,9 +21,7 @@ describe('gcoghpr', () => {
(upUser, upRepo, prAuthor, prBranch, prCommits = 0, prNumber = 0, currentBranch = 'master') => {
const localBranch = `${PR_LOCAL_BRANCH_PREFIX}-${!prNumber ? prBranch : `pr${prNumber}`}`;
const remoteUrl = `${PR_REMOTE_ALIAS_PREFIX}-${prAuthor}`;
const gitGetDefaultBranchCmd =
'(git show-ref --heads --quiet master && echo master) || ' +
'(git show-ref --heads --quiet main && echo main) || echo unknown-branch';
const gitGetDefaultBranchCmd = ALIASES.git.gdefb.getSpec().command;
const reportSuccessCmd = !prCommits ?
'withStyle(reset): ' +
'node --print "\'\'" && ' +
Expand Down

0 comments on commit 6630760

Please sign in to comment.