Skip to content

Commit

Permalink
Add wrapper function for git command
Browse files Browse the repository at this point in the history
  • Loading branch information
alfunx committed Nov 16, 2018
1 parent 07c2a57 commit 7823215
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions dotfiles
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,19 @@ _EOF_
}
# }}}

_git() {
git --git-dir="$dotfiles_dir" "$@"
}

# Init {{{
init_setup() {
mkdir -p "${XDG_CONFIG_HOME:-$HOME/.config}"
echo "dotfiles_dir=$dotfiles_dir" > "${XDG_CONFIG_HOME:-$HOME/.config}"/dotfiles.conf
sparse_tree > "$dotfiles_dir"/info/sparse-checkout
git --git-dir "$dotfiles_dir" config --local core.bare false
git --git-dir "$dotfiles_dir" config --local core.worktree ~
git --git-dir "$dotfiles_dir" config --local core.sparseCheckout true
git --git-dir "$dotfiles_dir" config --local status.showUntrackedFiles no
_git config --local core.bare false
_git config --local core.worktree ~
_git config --local core.sparseCheckout true
_git config --local status.showUntrackedFiles no
}

init() {
Expand All @@ -127,9 +131,9 @@ clone() {
git clone --bare "$1" "$dotfiles_dir" || error "failed to clone '$1'"
init_setup
# If there is no .gitignore yet, this will just clobber some comments
git --git-dir "$dotfiles_dir" show HEAD:.gitignore > "$dotfiles_dir"/info/exclude 2>/dev/null
git --git-dir "$dotfiles_dir" show HEAD:.gitattributes > "$dotfiles_dir"/info/attributes 2>/dev/null
git --git-dir "$dotfiles_dir" checkout
_git show HEAD:.gitignore > "$dotfiles_dir"/info/exclude 2>/dev/null
_git show HEAD:.gitattributes > "$dotfiles_dir"/info/attributes 2>/dev/null
_git checkout
}
# }}}

Expand All @@ -141,17 +145,17 @@ edit_info() {
else
printf '%s\n' "$@" >> "$infofile"
fi
git --git-dir="$dotfiles_dir" update-index --add --cacheinfo 10064,$(git --git-dir="$dotfiles_dir" hash-object -w "$infofile"),"$dotfile"
git --git-dir "$dotfiles_dir" checkout --quiet
_git update-index --add --cacheinfo 10064,$(_git hash-object -w "$infofile"),"$dotfile"
_git checkout --quiet
}

readme() {
local readme_file="$(mktemp -dt dotfiles.XXXXXX)/README.md"
git --git-dir="$dotfiles_dir" show :README.md > "$readme_file"
_git show :README.md > "$readme_file"
${EDITOR:-vim} "$readme_file"
git --git-dir="$dotfiles_dir" update-index --add --cacheinfo 10064,$(git --git-dir="$dotfiles_dir" hash-object -w "$readme_file"),README.md
_git update-index --add --cacheinfo 10064,$(_git hash-object -w "$readme_file"),README.md
rm -r "${readme_file%README.md}"
git --git-dir "$dotfiles_dir" checkout --quiet
_git checkout --quiet
}

# Main
Expand Down Expand Up @@ -180,5 +184,5 @@ case $dot_cmd in
$dot_cmd
;;
*)
git --git-dir="$dotfiles_dir" $dot_cmd "$@"
_git $dot_cmd "$@"
esac

0 comments on commit 7823215

Please sign in to comment.