initial commit
This commit is contained in:
8
bash/.git-formatter/scripts/__init__.py
Normal file
8
bash/.git-formatter/scripts/__init__.py
Normal file
@@ -0,0 +1,8 @@
|
||||
from .worktree import (
|
||||
add_worktree,
|
||||
remove_worktree,
|
||||
)
|
||||
from .commit import add_commit
|
||||
from .branch import (
|
||||
new_branch,
|
||||
)
|
9
bash/.git-formatter/scripts/branch.py
Normal file
9
bash/.git-formatter/scripts/branch.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from utils.branch_details import branch_details
|
||||
from utils.format import format_branch
|
||||
from utils.git_commands import git_checkout_branch
|
||||
|
||||
|
||||
def new_branch():
|
||||
branch_type, branch_id = branch_details()
|
||||
branch_name = format_branch(branch_type, branch_id)
|
||||
git_checkout_branch(branch_name)
|
19
bash/.git-formatter/scripts/commit.py
Normal file
19
bash/.git-formatter/scripts/commit.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from utils.format import format_commit
|
||||
from utils.git_commands import git_commit
|
||||
from utils.messages import (
|
||||
title,
|
||||
instructions,
|
||||
commit_instructions,
|
||||
)
|
||||
|
||||
|
||||
def add_commit(message=''):
|
||||
commit_title = f"{format_commit()}: "
|
||||
commit_message = message
|
||||
|
||||
if commit_message == '':
|
||||
title("Commit Message")
|
||||
instructions(commit_instructions)
|
||||
commit_message = input(commit_title)
|
||||
|
||||
git_commit(f"{commit_title}{commit_message}")
|
60
bash/.git-formatter/scripts/worktree.py
Normal file
60
bash/.git-formatter/scripts/worktree.py
Normal file
@@ -0,0 +1,60 @@
|
||||
import os
|
||||
import subprocess
|
||||
from .branch import branch_details
|
||||
from utils.format import format_branch
|
||||
from utils.git_commands import (
|
||||
git_add_worktree,
|
||||
git_remove_worktree,
|
||||
)
|
||||
from utils.messages import (
|
||||
title,
|
||||
instructions,
|
||||
worktree_instructions,
|
||||
)
|
||||
|
||||
|
||||
def add_worktree(worktree=None, auto_install=False):
|
||||
|
||||
# Check for bare repo
|
||||
try:
|
||||
with open('config') as git_config:
|
||||
content = ' '.join(git_config.readlines())
|
||||
if 'bare = true' in content:
|
||||
|
||||
# Ask for worktree folder name
|
||||
|
||||
if worktree is None:
|
||||
title('Create Worktree')
|
||||
instructions(worktree_instructions)
|
||||
worktree = input('Worktree Directory Name: ')
|
||||
|
||||
# Get branch details
|
||||
branch_type, branch_id = branch_details()
|
||||
|
||||
# Format branch name
|
||||
branch_name = format_branch(
|
||||
branch_type,
|
||||
branch_id,
|
||||
worktree,
|
||||
)
|
||||
|
||||
# Create worktree
|
||||
git_add_worktree(worktree, branch_name)
|
||||
|
||||
# Install NPM packages after worktree creation
|
||||
if auto_install:
|
||||
os.chdir(f"./{worktree}")
|
||||
|
||||
subprocess.run(['/bin/bash', '-i', '-c', 'nvm use'])
|
||||
subprocess.run(['npm', 'i'])
|
||||
|
||||
exit(0)
|
||||
|
||||
except Exception:
|
||||
print('No worktree found')
|
||||
exit(1)
|
||||
|
||||
|
||||
def remove_worktree(worktree):
|
||||
worktree_name = worktree if worktree else input('Worktree to remove: ')
|
||||
git_remove_worktree(worktree_name)
|
Reference in New Issue
Block a user