1
0
mirror of https://github.com/TheLocehiliosan/yadm synced 2025-06-05 17:13:58 +00:00

Print all git commands when is set.

This commit is contained in:
Christof Warlich 2025-01-03 08:45:20 +01:00
parent ec10041024
commit 9088981b6b

68
yadm
View File

@ -162,6 +162,10 @@ function main() {
} }
git_program() {
[[ -z $DEBUG ]] || printf "\e[1;32m%s\e[0m\n" "$GIT_PROGRAM ${*@Q}" >&2
"$GIT_PROGRAM" "$@"
}
# ****** Alternate Processing ****** # ****** Alternate Processing ******
@ -599,7 +603,7 @@ function alt() {
# determine all tracked files # determine all tracked files
local tracked_files=() local tracked_files=()
local IFS=$'\n' local IFS=$'\n'
for tracked_file in $("$GIT_PROGRAM" ls-files | LC_ALL=C sort); do for tracked_file in $(git_program ls-files | LC_ALL=C sort); do
tracked_files+=("$tracked_file") tracked_files+=("$tracked_file")
done done
@ -832,7 +836,7 @@ function clone() {
# remove existing if forcing the clone to happen anyway # remove existing if forcing the clone to happen anyway
[ -d "$YADM_REPO" ] && { [ -d "$YADM_REPO" ] && {
debug "Removing existing repo prior to clone" debug "Removing existing repo prior to clone"
"$GIT_PROGRAM" -C "$YADM_WORK" submodule deinit -f --all git_program -C "$YADM_WORK" submodule deinit -f --all
rm -rf "$YADM_REPO" rm -rf "$YADM_REPO"
} }
@ -843,7 +847,7 @@ function clone() {
# first clone without checkout # first clone without checkout
debug "Doing an initial clone of the repository" debug "Doing an initial clone of the repository"
(cd "$wc" && (cd "$wc" &&
"$GIT_PROGRAM" -c core.sharedrepository=0600 clone --no-checkout \ git_program -c core.sharedrepository=0600 clone --no-checkout \
--separate-git-dir="$YADM_REPO" "${args[@]}" repo.git) || { --separate-git-dir="$YADM_REPO" "${args[@]}" repo.git) || {
debug "Removing repo after failed clone" debug "Removing repo after failed clone"
rm -rf "$YADM_REPO" "$wc" rm -rf "$YADM_REPO" "$wc"
@ -853,12 +857,12 @@ function clone() {
rm -rf "$wc" rm -rf "$wc"
# then reset the index as the --no-checkout flag makes the index empty # then reset the index as the --no-checkout flag makes the index empty
"$GIT_PROGRAM" reset --quiet -- . git_program reset --quiet -- .
if [ "$YADM_WORK" = "$HOME" ]; then if [ "$YADM_WORK" = "$HOME" ]; then
debug "Determining if repo tracks private directories" debug "Determining if repo tracks private directories"
for private_dir in $(private_dirs all); do for private_dir in $(private_dirs all); do
found_log=$("$GIT_PROGRAM" log -n 1 -- "$private_dir" 2>/dev/null) found_log=$(git_program log -n 1 -- "$private_dir" 2>/dev/null)
if [ -n "$found_log" ]; then if [ -n "$found_log" ]; then
debug "Private directory $private_dir is tracked by repo" debug "Private directory $private_dir is tracked by repo"
assert_private_dirs "$private_dir" assert_private_dirs "$private_dir"
@ -872,11 +876,11 @@ function clone() {
cd_work "Clone" || return cd_work "Clone" || return
"$GIT_PROGRAM" ls-files --deleted | while IFS= read -r file; do git_program ls-files --deleted | while IFS= read -r file; do
"$GIT_PROGRAM" checkout -- ":/$file" git_program checkout -- ":/$file"
done done
if [ -n "$("$GIT_PROGRAM" ls-files --modified)" ]; then if [ -n "$(git_program ls-files --modified)" ]; then
local msg local msg
IFS='' read -r -d '' msg <<EOF IFS='' read -r -d '' msg <<EOF
**NOTE** **NOTE**
@ -928,7 +932,7 @@ EOF
# operate on the yadm repo's configuration file # operate on the yadm repo's configuration file
# this is always local to the machine # this is always local to the machine
"$GIT_PROGRAM" config "$@" git_program config "$@"
CHANGES_POSSIBLE=1 CHANGES_POSSIBLE=1
@ -936,7 +940,7 @@ EOF
# make sure parent folder of config file exists # make sure parent folder of config file exists
assert_parent "$YADM_CONFIG" assert_parent "$YADM_CONFIG"
# operate on the yadm configuration file # operate on the yadm configuration file
"$GIT_PROGRAM" config --file="$(mixed_path "$YADM_CONFIG")" "$@" git_program config --file="$(mixed_path "$YADM_CONFIG")" "$@"
fi fi
@ -1079,14 +1083,14 @@ function encrypt() {
fi fi
# offer to add YADM_ARCHIVE if untracked # offer to add YADM_ARCHIVE if untracked
archive_status=$("$GIT_PROGRAM" status --porcelain -uall "$(mixed_path "$YADM_ARCHIVE")" 2>/dev/null) archive_status=$(git_program status --porcelain -uall "$(mixed_path "$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 < /dev/tty read -r answer < /dev/tty
if [[ $answer =~ ^[yY]$ ]] ; then if [[ $answer =~ ^[yY]$ ]] ; then
"$GIT_PROGRAM" add "$(mixed_path "$YADM_ARCHIVE")" git_program add "$(mixed_path "$YADM_ARCHIVE")"
fi fi
fi fi
@ -1169,7 +1173,7 @@ function git_command() {
# pass commands through to git # pass commands through to git
debug "Running git command $GIT_PROGRAM $*" debug "Running git command $GIT_PROGRAM $*"
"$GIT_PROGRAM" "$@" git_program "$@"
return "$?" return "$?"
} }
@ -1224,13 +1228,13 @@ function init() {
# remove existing if forcing the init to happen anyway # remove existing if forcing the init to happen anyway
[ -d "$YADM_REPO" ] && { [ -d "$YADM_REPO" ] && {
debug "Removing existing repo prior to init" debug "Removing existing repo prior to init"
"$GIT_PROGRAM" -C "$YADM_WORK" submodule deinit -f --all git_program -C "$YADM_WORK" submodule deinit -f --all
rm -rf "$YADM_REPO" rm -rf "$YADM_REPO"
} }
# init a new bare repo # init a new bare repo
debug "Init new repo" debug "Init new repo"
"$GIT_PROGRAM" init --shared=0600 --bare "$(mixed_path "$YADM_REPO")" "$@" git_program init --shared=0600 --bare "$(mixed_path "$YADM_REPO")" "$@"
configure_repo configure_repo
CHANGES_POSSIBLE=1 CHANGES_POSSIBLE=1
@ -1325,7 +1329,7 @@ function list() {
fi fi
# list tracked files # list tracked files
"$GIT_PROGRAM" ls-files git_program ls-files
} }
@ -1395,18 +1399,18 @@ function upgrade() {
# Must absorb git dirs, otherwise deinit below will fail for modules that have # Must absorb git dirs, otherwise deinit below will fail for modules that have
# been cloned first and then added as a submodule. # been cloned first and then added as a submodule.
"$GIT_PROGRAM" submodule absorbgitdirs git_program submodule absorbgitdirs
local submodule_status local submodule_status
submodule_status=$("$GIT_PROGRAM" -C "$YADM_WORK" submodule status) submodule_status=$(git_program -C "$YADM_WORK" submodule status)
while read -r sha submodule rest; do while read -r sha submodule rest; do
[ "$submodule" == "" ] && continue [ "$submodule" == "" ] && continue
if [[ "$sha" = -* ]]; then if [[ "$sha" = -* ]]; then
continue continue
fi fi
"$GIT_PROGRAM" -C "$YADM_WORK" submodule deinit ${FORCE:+-f} -- "$submodule" || { git_program -C "$YADM_WORK" submodule deinit ${FORCE:+-f} -- "$submodule" || {
for other in "${submodules[@]}"; do for other in "${submodules[@]}"; do
"$GIT_PROGRAM" -C "$YADM_WORK" submodule update --init --recursive -- "$other" git_program -C "$YADM_WORK" submodule update --init --recursive -- "$other"
done done
error_out "Unable to upgrade. Could not deinit submodule $submodule" error_out "Unable to upgrade. Could not deinit submodule $submodule"
} }
@ -1431,8 +1435,8 @@ function upgrade() {
echo "Moving $LEGACY_ARCHIVE to $YADM_ARCHIVE" echo "Moving $LEGACY_ARCHIVE to $YADM_ARCHIVE"
assert_parent "$YADM_ARCHIVE" assert_parent "$YADM_ARCHIVE"
# test to see if path is "tracked" in repo, if so 'git mv' must be used # test to see if path is "tracked" in repo, if so 'git mv' must be used
if "$GIT_PROGRAM" ls-files --error-unmatch "$LEGACY_ARCHIVE" &> /dev/null; then if git_program ls-files --error-unmatch "$LEGACY_ARCHIVE" &> /dev/null; then
"$GIT_PROGRAM" mv "$LEGACY_ARCHIVE" "$YADM_ARCHIVE" && repo_updates=1 git_program mv "$LEGACY_ARCHIVE" "$YADM_ARCHIVE" && repo_updates=1
else else
mv -i "$LEGACY_ARCHIVE" "$YADM_ARCHIVE" mv -i "$LEGACY_ARCHIVE" "$YADM_ARCHIVE"
fi fi
@ -1453,8 +1457,8 @@ function upgrade() {
echo "Moving $legacy_path to $new_filename" echo "Moving $legacy_path to $new_filename"
assert_parent "$new_filename" assert_parent "$new_filename"
# test to see if path is "tracked" in repo, if so 'git mv' must be used # test to see if path is "tracked" in repo, if so 'git mv' must be used
if "$GIT_PROGRAM" ls-files --error-unmatch "$legacy_path" &> /dev/null; then if git_program ls-files --error-unmatch "$legacy_path" &> /dev/null; then
"$GIT_PROGRAM" mv "$legacy_path" "$new_filename" && repo_updates=1 git_program mv "$legacy_path" "$new_filename" && repo_updates=1
else else
mv -i "$legacy_path" "$new_filename" mv -i "$legacy_path" "$new_filename"
fi fi
@ -1463,7 +1467,7 @@ function upgrade() {
# handle submodules, which need to be reinitialized # handle submodules, which need to be reinitialized
for submodule in "${submodules[@]}"; do for submodule in "${submodules[@]}"; do
"$GIT_PROGRAM" -C "$YADM_WORK" submodule update --init --recursive -- "$submodule" git_program -C "$YADM_WORK" submodule update --init --recursive -- "$submodule"
done done
[ "$actions_performed" -eq 0 ] && \ [ "$actions_performed" -eq 0 ] && \
@ -1479,7 +1483,7 @@ function upgrade() {
function version() { function version() {
echo "bash version $BASH_VERSION" echo "bash version $BASH_VERSION"
printf " "; "$GIT_PROGRAM" --version printf " "; git_program --version
echo "yadm version $VERSION" echo "yadm version $VERSION"
exit_with_hook 0 exit_with_hook 0
@ -1749,7 +1753,7 @@ function configure_paths() {
# obtain YADM_WORK from repo if it exists # obtain YADM_WORK from repo if it exists
if [ -d "$GIT_DIR" ]; then if [ -d "$GIT_DIR" ]; then
local work local work
work=$(unix_path "$("$GIT_PROGRAM" config core.worktree)") work=$(unix_path "$(git_program config core.worktree)")
[ -n "$work" ] && YADM_WORK="$work" [ -n "$work" ] && YADM_WORK="$work"
fi fi
@ -1768,16 +1772,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_PROGRAM" 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_PROGRAM" config core.worktree "$(mixed_path "$YADM_WORK")" git_program config core.worktree "$(mixed_path "$YADM_WORK")"
# by default, do not show untracked files and directories # by default, do not show untracked files and directories
"$GIT_PROGRAM" 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_PROGRAM" config yadm.managed 'true' git_program config yadm.managed 'true'
} }
@ -1791,7 +1795,7 @@ function set_operating_system() {
case "$OPERATING_SYSTEM" in case "$OPERATING_SYSTEM" in
CYGWIN*|MINGW*|MSYS*) CYGWIN*|MINGW*|MSYS*)
git_version="$("$GIT_PROGRAM" --version 2>/dev/null)" git_version="$(git_program --version 2>/dev/null)"
if [[ "$git_version" =~ windows ]] ; then if [[ "$git_version" =~ windows ]] ; then
USE_CYGPATH=1 USE_CYGPATH=1
fi fi