-
Notifications
You must be signed in to change notification settings - Fork 17
Fix multi remote error、add git hist
and update the install.sh
#4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
a0a475f
1483400
e14ed45
ecff24c
e110864
6d50944
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,7 +1,8 @@ | ||||||||||||||||||
#!/bin/sh | ||||||||||||||||||
|
||||||||||||||||||
first() { | ||||||||||||||||||
branch=`git symbolic-ref refs/remotes/origin/HEAD` | ||||||||||||||||||
git log --reverse --pretty=%H $branch | head -1 | xargs git checkout | ||||||||||||||||||
REMOTE=$(git remote) | ||||||||||||||||||
branch=${1:-$(git symbolic-ref "refs/remotes/$REMOTE/HEAD")} | ||||||||||||||||||
git log --reverse --pretty=%H "$branch" | head -1 | xargs git checkout | ||||||||||||||||||
Comment on lines
+5
to
+6
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Improve error handling and command consistency. The script needs proper error handling and consistent command usage. Apply this diff to improve robustness: - branch=${1:-$(git symbolic-ref "refs/remotes/$REMOTE/HEAD")}
- git log --reverse --pretty=%H "$branch" | head -1 | xargs git checkout
+ if ! branch=${1:-$(git symbolic-ref "refs/remotes/$REMOTE/HEAD" 2>/dev/null)}; then
+ echo "Error: Failed to get default branch for remote '$REMOTE'" >&2
+ exit 1
+ fi
+ commit=$(git log --reverse --pretty=%H -n1 "$branch") || exit 1
+ git checkout "$commit" || exit 1 📝 Committable suggestion
Suggested change
|
||||||||||||||||||
} | ||||||||||||||||||
first "$@" |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,14 @@ | ||||||||||||||||||||||||||||||||||||||
#!/bin/sh | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
hist() { | ||||||||||||||||||||||||||||||||||||||
if test -z $1;then | ||||||||||||||||||||||||||||||||||||||
REMOTE=$(git remote) | ||||||||||||||||||||||||||||||||||||||
params=${1:-$(git symbolic-ref "refs/remotes/$REMOTE/HEAD")} | ||||||||||||||||||||||||||||||||||||||
else | ||||||||||||||||||||||||||||||||||||||
params="$@" | ||||||||||||||||||||||||||||||||||||||
fi | ||||||||||||||||||||||||||||||||||||||
Comment on lines
+4
to
+9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Improve parameter handling and add error handling. The parameter handling can be improved with better shell syntax. Apply this diff: - if test -z $1;then
+ if [ $# -eq 0 ]; then
REMOTE=$(git remote | head -n1)
+ if [ $(git remote | wc -l) -gt 1 ]; then
+ echo "Warning: Multiple remotes found, using '$REMOTE'" >&2
+ fi
- params=${1:-$(git symbolic-ref "refs/remotes/$REMOTE/HEAD")}
+ if ! params=$(git symbolic-ref "refs/remotes/$REMOTE/HEAD" 2>/dev/null); then
+ echo "Error: Failed to get default branch for remote '$REMOTE'" >&2
+ exit 1
+ fi
else
- params="$@"
+ params="$*"
fi 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||
git log --color --graph --abbrev-commit \ | ||||||||||||||||||||||||||||||||||||||
--pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<author:%an == commitor:%cn>%Creset' \ | ||||||||||||||||||||||||||||||||||||||
$params | ||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
hist "$@" |
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,7 +1,8 @@ | ||||||||||||||||||
#!/bin/sh | ||||||||||||||||||
|
||||||||||||||||||
last() { | ||||||||||||||||||
branch=`git symbolic-ref refs/remotes/origin/HEAD` | ||||||||||||||||||
git log --pretty=%H $branch | head -1 | xargs git checkout | ||||||||||||||||||
REMOTE=$(git remote) | ||||||||||||||||||
branch=${1:-$(git symbolic-ref "refs/remotes/$REMOTE/HEAD")} | ||||||||||||||||||
Comment on lines
+4
to
+5
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add error handling for multiple remote repositories. The Apply this diff to handle multiple remotes: - REMOTE=$(git remote)
+ REMOTE=$(git remote | head -n1)
+ if [ $(git remote | wc -l) -gt 1 ]; then
+ echo "Warning: Multiple remotes found, using '$REMOTE'"
+ fi 📝 Committable suggestion
Suggested change
|
||||||||||||||||||
git log -n 1 --pretty=%H "$branch" | git checkout | ||||||||||||||||||
Comment on lines
+5
to
+6
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add error handling and proper quoting. The script needs proper error handling for git commands and variable quoting. Apply this diff to improve robustness: - branch=${1:-$(git symbolic-ref "refs/remotes/$REMOTE/HEAD")}
- git log -n 1 --pretty=%H "$branch" | git checkout
+ if ! branch=${1:-$(git symbolic-ref "refs/remotes/$REMOTE/HEAD" 2>/dev/null)}; then
+ echo "Error: Failed to get default branch for remote '$REMOTE'" >&2
+ exit 1
+ fi
+ commit=$(git log -n 1 --pretty=%H "$branch") || exit 1
+ git checkout "$commit" || exit 1 📝 Committable suggestion
Suggested change
|
||||||||||||||||||
} | ||||||||||||||||||
last "$@" | ||||||||||||||||||
last "$@" |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,12 +1,13 @@ | ||||||||||||||||||||||
#!/bin/sh | ||||||||||||||||||||||
|
||||||||||||||||||||||
next() { | ||||||||||||||||||||||
branch=`git symbolic-ref refs/remotes/origin/HEAD` | ||||||||||||||||||||||
REMOTE=$(git remote) | ||||||||||||||||||||||
branch=$(git symbolic-ref "refs/remotes/$REMOTE/HEAD") | ||||||||||||||||||||||
Comment on lines
+4
to
+5
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix indentation and add error handling for multiple remotes. The script has inconsistent indentation and needs proper handling of multiple remotes. Apply this diff: - REMOTE=$(git remote)
- branch=$(git symbolic-ref "refs/remotes/$REMOTE/HEAD")
+ REMOTE=$(git remote | head -n1)
+ if [ $(git remote | wc -l) -gt 1 ]; then
+ echo "Warning: Multiple remotes found, using '$REMOTE'" >&2
+ fi
+ if ! branch=$(git symbolic-ref "refs/remotes/$REMOTE/HEAD" 2>/dev/null); then
+ echo "Error: Failed to get default branch for remote '$REMOTE'" >&2
+ exit 1
+ fi 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||
if [ -z "$1" ]; then | ||||||||||||||||||||||
n=1 | ||||||||||||||||||||||
else | ||||||||||||||||||||||
n=$1 | ||||||||||||||||||||||
fi | ||||||||||||||||||||||
git log --reverse --pretty=%H $branch | grep -A $n $(git rev-parse HEAD) | tail -1 | xargs git checkout | ||||||||||||||||||||||
git log --reverse --pretty=%H "$branch" | grep -A $n $(git rev-parse HEAD) | tail -1 | xargs git checkout | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add error handling for the commit lookup chain. The complex pipe chain needs proper error handling. Apply this diff: - git log --reverse --pretty=%H "$branch" | grep -A $n $(git rev-parse HEAD) | tail -1 | xargs git checkout
+ current_commit=$(git rev-parse HEAD) || exit 1
+ next_commit=$(git log --reverse --pretty=%H "$branch" | grep -A "$n" "$current_commit" | tail -1) || exit 1
+ if [ -z "$next_commit" ]; then
+ echo "Error: No next commit found" >&2
+ exit 1
+ fi
+ git checkout "$next_commit" || exit 1 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||
} | ||||||||||||||||||||||
next "$@" |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,35 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
[alias] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
hist = !"hist() { \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if test -z $1;then \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
REMOTE=\"$(git remote)\"; \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
params=\"${1:-$(git symbolic-ref \"refs/remotes/$REMOTE/HEAD\")}\"; \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
else \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
params=\"$@\"; \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
fi; \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
git log \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
--color \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
--graph \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
--abbrev-commit \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
--pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<author:%an == commitor:%cn>%Creset' \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$params; \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
};hist" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+2
to
+15
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add error handling to hist function. The Apply this diff to add error handling: hist = !"hist() { \
if test -z $1;then \
- REMOTE=\"$(git remote)\"; \
+ REMOTE=\"$(git remote 2>/dev/null)\"; \
+ if [ -z \"$REMOTE\" ]; then \
+ echo \"Error: No remote found\"; \
+ return 1; \
+ fi; \
params=\"${1:-$(git symbolic-ref \"refs/remotes/$REMOTE/HEAD\")}\"; \
+ if [ $? -ne 0 ]; then \
+ echo \"Error: Failed to get remote HEAD reference\"; \
+ return 1; \
+ fi; \
else \
params=\"$@\"; \
fi; \ 📝 Committable suggestion
Suggested change
🧰 Tools🪛 LanguageTool[style] ~2- (EN_EXCESSIVE_EXCLAMATION) |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
swc-first = !"first() { \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
REMOTE=\"$(git remote)\"; \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
branch=\"${1:-$(git symbolic-ref \"refs/remotes/$REMOTE/HEAD\")}\"; \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
git switch --detach $(git log --reverse --pretty=%H \"$branch\" | head -1); \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
};first" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+16
to
+20
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add consistent error handling to all navigation functions. The I can help implement error handling for these functions. Would you like me to generate the improved implementations? Also applies to: 21-25, 26-29 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
swc-last = !"last(){ \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
REMOTE=\"$(git remote)\"; \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
branch=\"${1:-$(git symbolic-ref \"refs/remotes/$REMOTE/HEAD\")}\"; \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
git switch --detach $(git log -n 1 --pretty=%H \"$branch\"); \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
};last" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
swc-prev = !"prev(){ \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
n=\"${1:-1}\"; \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
git checkout HEAD~$n; \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
};prev" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+26
to
+29
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Use consistent Git commands and add parameter validation.
Apply this diff to improve the implementation: swc-prev = !"prev(){ \
n=\"${1:-1}\"; \
- git checkout HEAD~$n; \
+ if ! [[ \"$n\" =~ ^[0-9]+$ ]]; then \
+ echo \"Error: Invalid number of commits\" >&2; \
+ return 1; \
+ fi; \
+ git switch --detach HEAD~$n; \
};prev" 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
swc-next = !"next(){ \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
REMOTE=\"$(git remote)\"; \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
branch=\"$(git symbolic-ref \"refs/remotes/$REMOTE/HEAD\")\"; \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
n=\"${1:-1}\"; \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
git switch --detach $(git log --reverse --pretty=%H \"$branch\" | grep -A $n $(git rev-parse HEAD) | tail -1); \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
};next" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
#!/bin/sh | ||
|
||
prev() { | ||
branch=`git symbolic-ref refs/remotes/origin/HEAD` | ||
if [ -z "$1" ]; then | ||
n=1 | ||
else | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,2 +1,6 @@ | ||||||||||||||||||||||||||||||||||||||||||||
#!/bin/sh | ||||||||||||||||||||||||||||||||||||||||||||
install -m 755 git-* /usr/local/bin | ||||||||||||||||||||||||||||||||||||||||||||
if test -f git-paging-alias.txt;then | ||||||||||||||||||||||||||||||||||||||||||||
git config --global --add include.path $(readlink -f git-paging-alias.txt) | ||||||||||||||||||||||||||||||||||||||||||||
else | ||||||||||||||||||||||||||||||||||||||||||||
install -m 755 git-* /usr/local/bin | ||||||||||||||||||||||||||||||||||||||||||||
fi | ||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+2
to
+6
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add error handling and fix security issues. The installation script has several issues that need to be addressed:
Apply this diff to fix the issues: #!/bin/sh
-if test -f git-paging-alias.txt;then
- git config --global --add include.path $(readlink -f git-paging-alias.txt)
+if test -f git-paging-alias.txt; then
+ if ! git config --global --add include.path "$(readlink -f git-paging-alias.txt)"; then
+ echo "Error: Failed to add git-paging-alias.txt to git config"
+ exit 1
+ fi
else
- install -m 755 git-* /usr/local/bin
+ if [ "$(id -u)" -ne 0 ]; then
+ echo "Error: Please run with sudo when installing to /usr/local/bin"
+ exit 1
+ fi
+ if ! install -m 755 git-* /usr/local/bin; then
+ echo "Error: Failed to install git-* files"
+ exit 1
+ fi
fi 📝 Committable suggestion
Suggested change
🧰 Tools🪛 Shellcheck (0.10.0)[warning] 3-3: Quote this to prevent word splitting. (SC2046) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix incorrect file name in the installation instructions.
The file name in the git config command is incorrect:
git-paging-ali.txt
git-paging-alias.txt