Skip to content

Commit 812c85e

Browse files
committed
feat(gitutils): ✨ add git pickscript for picking files from a specific folder
1 parent a44c30b commit 812c85e

2 files changed

Lines changed: 44 additions & 1 deletion

File tree

src/gitutils/_git-pick.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/bin/sh
2+
3+
# Function to print help and manage arguments
4+
eval $(
5+
zz_args "Pick files from a specific commit" $0 "$@" <<-help
6+
c commit commit commit sha to pick from (if not provided, will prompt)
7+
- path path path to restore (default: current directory)
8+
help
9+
)
10+
11+
#### Go to repository root
12+
cd "$(git rev-parse --show-toplevel)"
13+
14+
# If no commit is provided, use git getcommit to select one
15+
if [ -z "$commit" ]; then
16+
commit=$(git getcommit)
17+
if [ $? -ne 0 ] || [ -z "$commit" ]; then
18+
zz_log e "No commit selected or invalid commit"
19+
exit 1
20+
fi
21+
fi
22+
23+
# If no path is provided, use current prefix (relative to repo root)
24+
if [ -z "$path" ]; then
25+
path=$(git rev-parse --show-prefix)
26+
# If path is empty (we're at repo root), use current directory
27+
if [ -z "$path" ]; then
28+
path="."
29+
fi
30+
fi
31+
32+
zz_log i "Picking files from commit: $commit"
33+
zz_log i "Target path: $path"
34+
35+
# Execute the git restore command
36+
git restore --source="$commit" --staged --worktree "$path"
37+
38+
if [ $? -eq 0 ]; then
39+
zz_log s "Successfully picked files from commit $commit to $path"
40+
else
41+
zz_log e "Failed to pick files from commit $commit"
42+
exit 1
43+
fi

src/gitutils/devcontainer-feature.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"id": "gitutils",
33
"name": "Git Aliases",
44
"description": "A feature to add useful Git aliases to your shell.",
5-
"version": "5.24.1",
5+
"version": "5.25.0",
66
"dependsOn": {
77
"ghcr.io/devcontainers/features/node:1": "lts",
88
"ghcr.io/tomgrv/devcontainer-features/common-utils:3": {

0 commit comments

Comments
 (0)