#!/bin/bash
# g3 - git distributed VCS helper

set -e

source '/home/zwelch/src/mcf/mcsh-release/install/share/mcsh/mcsh.sh'

lib_load 'sys/tool/git'


######
# Check

g3_config_init() {
	script_setting_vars -ro g3_gitdir
	g3_gitdir=$script_datadir/git

	script_setting_vars -ro g3_status_default
	g3_status_default=repo
}

g3_config_check() {
	:
}

######
# Working Copy CLI

g3_status() {
	if [ "$*" ]; then
		cmd_dispatch "$@"
	else
		git_status_${g3_status_default}
	fi
}

g3_status_usage() {
	cat <<USAGE
...
Git Status Commands
	new				Shows tracked and untracked
	repo				Shows only tracked files (default)
	all				Shows all files (untracked and ignored)
USAGE
}

g3_status_new() { git_status_tracked normal "$@"; }
g3_status_repo() { git_status_tracked no "$@"; }
g3_status_all() { git_status_tracked all "$@"; }


######
# Index CLI

g3_index() { cmd_dispatch "$@"; }
g3_index_usage() {
	cat <<USAGE
...
Git Staging Commands:
	reset				Resets the index but retains changes
	nuke				Resets the index and drops changes
USAGE
}
g3_index_reset() { git_reset --soft HEAD "$@"; }
g3_index_nuke() { git_reset --hard HEAD "$@"; }


######
# Commit CLI

g3_commit() {
	if [ "$*" ]; then
		cmd_dispatch "$@"
	else
		git_commit_index
	fi
}

g3_commit_usage() {
	cat <<USAGE
...
Git Commit Creation:
	index 				Commit only staged files
	fast [<path>+]			Adds all tracked files and commits
	all [<path>+]			Adds tracked and untracked files

Git Commit Destruction:
	drop [<count>]			Drops some numer of commits (rollback)
USAGE
# TODO	wizard [<path>+]		Commits using guided process
# TODO	auto [<path>+]			Automatic commit process
# TODO	custom [<path>+]		Custom commit process
}

g3_commit_index() { git_commit_index; }
g3_commit_fast() { git_commit_fast "$@"; }
g3_commit_all() { git_commit_all "$@"; }
g3_commit_drop() { git_commit_drop "$@"; }


######
# Check

g3_svn() {
	lib_load 'sys/tool/git-svn'
	cmd_dispatch "$@"
}
g3_svn_usage() {
	cat <<USAGE
...
Git Subversion Commands:
	clone <url> [<name>]		Creates a clone of a Subversion repo
	update 				Updates the upstream branch
	push 				Pushes changes on the current head
USAGE
}

g3_svn_clone() {
	min_max_args 1 2 "$@"
	local url=$1
	local name=${2:-$1##*/}
	git_svn_clone "$url" "$name"
}

g3_svn_update() {
	:
}

g3_svn_push() {
	:
}


######
# Check

g3_check() {
	local git_repodir=$cmd_tempdir
	run_pushd "$cmd_tempdir"
	git_create test "A sample git repository"
	run_in_dir test g3_check_repo
}

g3_check_repo() {
	touch a b
	git_add a b
	git_status
	git_commit -m 'a,b: new files'

	git_tag v1
	git_tag_delete v1

	touch c
	git_status
	git_add c
	git_status
	git_commit -m 'c: new file'

	echo >>b
	echo >>c
	git_commit -m 'b,c: changes' .

	git_log --stat
}


######
# Main

g3_desc() { echo "git helper"; }
g3_usage() {
	cat <<USAGE
<cmd> ...
Git Commands:
	status ...			Reports working copy status
	index ...			Manages indexes of
	commit ...			Commits changes of

Git Extensions:
	svn ...				Commands for ``git svn`` support
USAGE
}
g3_help() {
	cat <<HELP
g3 is a git helper tool.  It is part of the mcsh package.
HELP
}

app_run "$@"

View the Developer Guide Index

View the Reference Manual Index


Generated on Fri Jul 28 14:34:43 PDT 2017 by mcsh d14 v0.23.0.