-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathArgcfile.sh
More file actions
executable file
·105 lines (86 loc) · 2.95 KB
/
Argcfile.sh
File metadata and controls
executable file
·105 lines (86 loc) · 2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env bash
# @describe Helper scripts for managing the dotfiles.
set -eu
# @cmd Pull the latest verison and sync
# @flag --bootstrap Run the bootstrap script.
pull() {
if [[ ! -d .jj ]]; then
./tasks/90-jj.sh
fi
# Update git remote
jj git fetch --quiet
# Check signature on new leaf
local sig=$(jj log -r master@origin -GT 'signature.status()')
if [[ "$sig" != "good" ]]; then
jj show --no-pager --no-patch master@origin
echo "$sig signature on master@origin" >&2
exit 1
fi
# Get the current commit hash before rebasing
before_commit=$(jj log -r @ -GT 'commit_id')
# Rebase current commits on top
jj rebase -d master --quiet
# If the previous rebase resulted in a merge conflict on a jj config
# file, it will prevent jj from starting, so we won't be able to undo the
# changes. So we will bypass the jj config for this step.
export JJ_CONFIG=
if [[ "$(jj log -r @ -GT 'conflict')" == "true" ]]; then
jj status
echo "" >&2
echo "Failed to update" >&2
jj undo
exit 1
fi
# Restore jj config
unset JJ_CONFIG
# Get the new commit hash after rebasing
after_commit=$(jj log -r @ -GT 'commit_id')
dfm link
if [[ "$before_commit" != "$after_commit" ]]; then
jj l -r "$before_commit..@" --reversed
else
echo "No new changes"
fi
jj default-status
if [[ "${argc_bootstrap:+1}" ]]; then
./bootstrap.sh
elif [[ "$before_commit" != "$after_commit" ]]; then
# Get list of modified files between the commits
modified_files=$(jj diff --name-only --from "$before_commit" --to "$after_commit")
# Check if any files in tasks directory were modified
tasks_modified=$(echo "$modified_files" | grep -E '^tasks/' || true)
if [[ -n "$tasks_modified" && ! "${argc_bootstrap:+1}" ]]; then
echo -e "\033[1;33m" >&2
echo "WARNING: Files in the 'tasks' directory have been modified!" >&2
echo "Modified task files:" >&2
# shellcheck disable=SC2001
echo "$tasks_modified" | sed 's/^/ /' >&2
echo >&2
echo "To fully update: @argc dotfiles pull --bootstrap" >&2
echo -e "\033[0m" >&2
fi
fi
}
# @cmd Push the changes to the repository.
#
# This amends the latest commit to sign it, and uses --force-with-lease
push() {
# JJ does not support automatically detecting the ssh key
# https://github.com/jj-vcs/jj/issues/6688
jj config set --repo signing.key "$(ssh-add -L | tail -1)"
local sig=$(jj log -r master -GT 'signature.status()')
if [[ "$sig" != "good" ]]; then
jj --quiet sign -r master
fi
git push git@gitlab.com:CGamesPlay/dotfiles.git master --force-with-lease=master:origin/master
git fetch origin
}
# @cmd Find files that maybe should be added to DFM.
find-unmanaged() {
echo "The following files are in directories controlled by DFM, but are not themselves in DFM."
find files -type d -not -name files \
| sed 's/^files/'$(echo ~ | sed 's/\//\\\//g')'/' \
| xargs -I {} find {} -maxdepth 1 -type f -not -name .DS_Store \
| grep -vE '.local/bin/|.ssh/id_'
}
eval "$(argc --argc-eval "$0" "$@")"