Allow Git program to be configured via yadm.git-program (#30)
This commit is contained in:
parent
25d3123988
commit
2a956d15ad
1 changed files with 36 additions and 27 deletions
63
yadm
63
yadm
|
@ -30,6 +30,7 @@ YADM_ENCRYPT="encrypt"
|
||||||
YADM_ARCHIVE="files.gpg"
|
YADM_ARCHIVE="files.gpg"
|
||||||
|
|
||||||
GPG_PROGRAM="gpg"
|
GPG_PROGRAM="gpg"
|
||||||
|
GIT_PROGRAM="git"
|
||||||
LS_PROGRAM="/bin/ls"
|
LS_PROGRAM="/bin/ls"
|
||||||
|
|
||||||
#; flag when something may have changes (which prompts auto actions to be performed)
|
#; flag when something may have changes (which prompts auto actions to be performed)
|
||||||
|
@ -112,7 +113,7 @@ function alt() {
|
||||||
match="^(.+)##($match_system|$match_system.$match_host|$match_system.$match_host.$match_user|())$"
|
match="^(.+)##($match_system|$match_system.$match_host|$match_system.$match_host.$match_user|())$"
|
||||||
|
|
||||||
#; process relative to YADM_WORK
|
#; process relative to YADM_WORK
|
||||||
YADM_WORK=$(git config core.worktree)
|
YADM_WORK=$("$GIT_PROGRAM" config core.worktree)
|
||||||
cd "$YADM_WORK" || {
|
cd "$YADM_WORK" || {
|
||||||
debug "Alternates not processed, unable to cd to $YADM_WORK"
|
debug "Alternates not processed, unable to cd to $YADM_WORK"
|
||||||
return
|
return
|
||||||
|
@ -125,7 +126,7 @@ function alt() {
|
||||||
#; for every file which matches the above regex, create a symlink
|
#; for every file which matches the above regex, create a symlink
|
||||||
last_linked=''
|
last_linked=''
|
||||||
local IFS=$'\n'
|
local IFS=$'\n'
|
||||||
for tracked_file in $(git ls-files | sort) $(cat "$YADM_ENCRYPT" 2>/dev/null); do
|
for tracked_file in $("$GIT_PROGRAM" ls-files | sort) $(cat "$YADM_ENCRYPT" 2>/dev/null); do
|
||||||
tracked_file="$YADM_WORK/$tracked_file"
|
tracked_file="$YADM_WORK/$tracked_file"
|
||||||
#; process both the path, and it's parent directory
|
#; process both the path, and it's parent directory
|
||||||
for alt_path in "$tracked_file" "${tracked_file%/*}"; do
|
for alt_path in "$tracked_file" "${tracked_file%/*}"; do
|
||||||
|
@ -154,26 +155,27 @@ function clean() {
|
||||||
function clone() {
|
function clone() {
|
||||||
|
|
||||||
#; clone will begin with a bare repo
|
#; clone will begin with a bare repo
|
||||||
init
|
local empty=
|
||||||
|
init $empty
|
||||||
|
|
||||||
#; add the specified remote, and configure the repo to track origin/master
|
#; add the specified remote, and configure the repo to track origin/master
|
||||||
debug "Adding remote to new repo"
|
debug "Adding remote to new repo"
|
||||||
git remote add origin "$1"
|
"$GIT_PROGRAM" remote add origin "$@"
|
||||||
debug "Configuring new repo to track origin/master"
|
debug "Configuring new repo to track origin/master"
|
||||||
git config branch.master.remote origin
|
"$GIT_PROGRAM" config branch.master.remote origin
|
||||||
git config branch.master.merge refs/heads/master
|
"$GIT_PROGRAM" config branch.master.merge refs/heads/master
|
||||||
|
|
||||||
#; fetch / merge (and possibly fallback to reset)
|
#; fetch / merge (and possibly fallback to reset)
|
||||||
debug "Doing an initial fetch of the origin"
|
debug "Doing an initial fetch of the origin"
|
||||||
git fetch origin || {
|
"$GIT_PROGRAM" fetch origin || {
|
||||||
debug "Removing repo after failed clone"
|
debug "Removing repo after failed clone"
|
||||||
rm -rf "$YADM_REPO"
|
rm -rf "$YADM_REPO"
|
||||||
error_out "Unable to fetch origin $1"
|
error_out "Unable to fetch origin $1"
|
||||||
}
|
}
|
||||||
debug "Doing an initial merge of origin/master"
|
debug "Doing an initial merge of origin/master"
|
||||||
git merge origin/master || {
|
"$GIT_PROGRAM" merge origin/master || {
|
||||||
debug "Merge failed, doing a reset."
|
debug "Merge failed, doing a reset."
|
||||||
git reset origin/master
|
"$GIT_PROGRAM" reset origin/master
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
**NOTE**
|
**NOTE**
|
||||||
Merging origin/master failed.
|
Merging origin/master failed.
|
||||||
|
@ -194,9 +196,6 @@ EOF
|
||||||
|
|
||||||
function config() {
|
function config() {
|
||||||
|
|
||||||
#; ensure we have a file, even if empty
|
|
||||||
[ -f "$YADM_CONFIG" ] || touch "$YADM_CONFIG"
|
|
||||||
|
|
||||||
if [ -z "$*" ] ; then
|
if [ -z "$*" ] ; then
|
||||||
#; with no parameters, provide some helpful documentation
|
#; with no parameters, provide some helpful documentation
|
||||||
echo TODO: Print help about available yadm configurations
|
echo TODO: Print help about available yadm configurations
|
||||||
|
@ -212,7 +211,7 @@ function decrypt() {
|
||||||
require_gpg
|
require_gpg
|
||||||
require_archive
|
require_archive
|
||||||
|
|
||||||
YADM_WORK=$(git config core.worktree)
|
YADM_WORK=$("$GIT_PROGRAM" config core.worktree)
|
||||||
|
|
||||||
if [ "$DO_LIST" = "YES" ] ; then
|
if [ "$DO_LIST" = "YES" ] ; then
|
||||||
tar_option="t"
|
tar_option="t"
|
||||||
|
@ -238,7 +237,7 @@ function encrypt() {
|
||||||
require_ls
|
require_ls
|
||||||
|
|
||||||
#; process relative to YADM_WORK
|
#; process relative to YADM_WORK
|
||||||
YADM_WORK=$(git config core.worktree)
|
YADM_WORK=$("$GIT_PROGRAM" config core.worktree)
|
||||||
cd "$YADM_WORK" || {
|
cd "$YADM_WORK" || {
|
||||||
debug "Encryption not processed, unable to cd to $YADM_WORK"
|
debug "Encryption not processed, unable to cd to $YADM_WORK"
|
||||||
return
|
return
|
||||||
|
@ -275,14 +274,14 @@ function encrypt() {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#; offer to add YADM_ARCHIVE if untracked
|
#; offer to add YADM_ARCHIVE if untracked
|
||||||
archive_status=$(git status --porcelain -uall "$YADM_ARCHIVE" 2>/dev/null)
|
archive_status=$("$GIT_PROGRAM" status --porcelain -uall "$YADM_ARCHIVE" 2>/dev/null)
|
||||||
archive_regex="^\?\?"
|
archive_regex="^\?\?"
|
||||||
if [[ $archive_status =~ $archive_regex ]] ; then
|
if [[ $archive_status =~ $archive_regex ]] ; then
|
||||||
echo "It appears that $YADM_ARCHIVE is not tracked by yadm's repository."
|
echo "It appears that $YADM_ARCHIVE is not tracked by yadm's repository."
|
||||||
echo "Would you like to add it now? (y/n)"
|
echo "Would you like to add it now? (y/n)"
|
||||||
read -r answer
|
read -r answer
|
||||||
if [[ $answer =~ ^[yY]$ ]] ; then
|
if [[ $answer =~ ^[yY]$ ]] ; then
|
||||||
git add "$YADM_ARCHIVE"
|
"$GIT_PROGRAM" add "$YADM_ARCHIVE"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -302,7 +301,7 @@ function git_command() {
|
||||||
CHANGES_POSSIBLE=1
|
CHANGES_POSSIBLE=1
|
||||||
|
|
||||||
#; pass commands through to git
|
#; pass commands through to git
|
||||||
git "$@"
|
"$GIT_PROGRAM" "$@"
|
||||||
return "$?"
|
return "$?"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -355,7 +354,7 @@ function init() {
|
||||||
|
|
||||||
#; init a new bare repo
|
#; init a new bare repo
|
||||||
debug "Init new repo"
|
debug "Init new repo"
|
||||||
git init --shared=0600 --bare "$YADM_REPO"
|
"$GIT_PROGRAM" init --shared=0600 --bare "$YADM_REPO" "$@"
|
||||||
configure_repo
|
configure_repo
|
||||||
|
|
||||||
CHANGES_POSSIBLE=1
|
CHANGES_POSSIBLE=1
|
||||||
|
@ -368,7 +367,7 @@ function list() {
|
||||||
|
|
||||||
#; process relative to YADM_WORK when --all is specified
|
#; process relative to YADM_WORK when --all is specified
|
||||||
if [ -n "$LIST_ALL" ] ; then
|
if [ -n "$LIST_ALL" ] ; then
|
||||||
YADM_WORK=$(git config core.worktree)
|
YADM_WORK=$("$GIT_PROGRAM" config core.worktree)
|
||||||
cd "$YADM_WORK" || {
|
cd "$YADM_WORK" || {
|
||||||
debug "List not processed, unable to cd to $YADM_WORK"
|
debug "List not processed, unable to cd to $YADM_WORK"
|
||||||
return
|
return
|
||||||
|
@ -376,7 +375,7 @@ function list() {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#; list tracked files
|
#; list tracked files
|
||||||
git ls-files
|
"$GIT_PROGRAM" ls-files
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -387,7 +386,7 @@ function perms() {
|
||||||
#; TODO: prevent repeats in the files changed
|
#; TODO: prevent repeats in the files changed
|
||||||
|
|
||||||
#; process relative to YADM_WORK
|
#; process relative to YADM_WORK
|
||||||
YADM_WORK=$(git config core.worktree)
|
YADM_WORK=$("$GIT_PROGRAM" config core.worktree)
|
||||||
cd "$YADM_WORK" || {
|
cd "$YADM_WORK" || {
|
||||||
debug "Perms not processed, unable to cd to $YADM_WORK"
|
debug "Perms not processed, unable to cd to $YADM_WORK"
|
||||||
return
|
return
|
||||||
|
@ -517,16 +516,16 @@ function configure_repo() {
|
||||||
debug "Configuring new repo"
|
debug "Configuring new repo"
|
||||||
|
|
||||||
#; change bare to false (there is a working directory)
|
#; change bare to false (there is a working directory)
|
||||||
git config core.bare 'false'
|
"$GIT_PROGRAM" config core.bare 'false'
|
||||||
|
|
||||||
#; set the worktree for the yadm repo
|
#; set the worktree for the yadm repo
|
||||||
git config core.worktree "$YADM_WORK"
|
"$GIT_PROGRAM" config core.worktree "$YADM_WORK"
|
||||||
|
|
||||||
#; by default, do not show untracked files and directories
|
#; by default, do not show untracked files and directories
|
||||||
git config status.showUntrackedFiles no
|
"$GIT_PROGRAM" config status.showUntrackedFiles no
|
||||||
|
|
||||||
#; possibly used later to ensure we're working on the yadm repo
|
#; possibly used later to ensure we're working on the yadm repo
|
||||||
git config yadm.managed 'true'
|
"$GIT_PROGRAM" config yadm.managed 'true'
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -578,8 +577,18 @@ function require_encrypt() {
|
||||||
[ -f "$YADM_ENCRYPT" ] || error_out "$YADM_ENCRYPT does not exist. did you forget to create it?"
|
[ -f "$YADM_ENCRYPT" ] || error_out "$YADM_ENCRYPT does not exist. did you forget to create it?"
|
||||||
}
|
}
|
||||||
function require_git() {
|
function require_git() {
|
||||||
command -v git >/dev/null 2>&1 || \
|
local alt_git
|
||||||
error_out "This functionality requires Git to be installed, but the command git cannot be located."
|
alt_git="$(config yadm.git-program)"
|
||||||
|
|
||||||
|
local more_info
|
||||||
|
more_info=""
|
||||||
|
|
||||||
|
if [ "$alt_git" != "" ] ; then
|
||||||
|
GIT_PROGRAM="$alt_git"
|
||||||
|
more_info="\nThis command has been set via the yadm.git-program configuration."
|
||||||
|
fi
|
||||||
|
command -v "$GIT_PROGRAM" >/dev/null 2>&1 || \
|
||||||
|
error_out "This functionality requires Git to be installed, but the command '$GIT_PROGRAM' cannot be located.$more_info"
|
||||||
}
|
}
|
||||||
function require_gpg() {
|
function require_gpg() {
|
||||||
local alt_gpg
|
local alt_gpg
|
||||||
|
|
Loading…
Reference in a new issue