Skip to content

Commit 5125750

Browse files
author
Bhavi Dhingra
committed
fix grestorestaged
1 parent a704211 commit 5125750

File tree

4 files changed

+9
-8
lines changed

4 files changed

+9
-8
lines changed

cmd/gadd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ source "$__CUSTOM_CONSOLE_UTIL"/__split_str
1313

1414
function main() {
1515

16-
numUnstagedFiles=$(git status --short | grep "^.[A-Z?] " -c)
16+
local numUnstagedFiles=$(git status --short | grep "^.[A-Z?] " -c)
1717
if [[ $numUnstagedFiles -eq 0 ]]; then
1818
gstatus
1919
echo

cmd/grestorestaged

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ source "$__CUSTOM_CONSOLE_UTIL"/__split_str
1212

1313
function main() {
1414

15-
numStagedFiles=$(git status --short | grep "^[A-Z] " -c)
15+
local numStagedFiles=$(git status --short | grep "^[A-Z]" -c)
1616
if [[ $numStagedFiles -eq 0 ]]; then
1717
gstatus
1818
echo
@@ -23,10 +23,10 @@ function main() {
2323
__intend_to_add_untracked_files
2424

2525
if [[ $# -gt 0 ]]; then
26-
git status --short | grep "^[A-Z] " | read_and_restore_staged_files
26+
git status --short | grep "^[A-Z]" | read_and_restore_staged_files
2727
else
2828
local GRESTORESTAGED_HEADER="$(__grestorestaged_header)"
29-
git status --short | grep "^[A-Z] " |\
29+
git status --short | grep "^[A-Z]" |\
3030
fzf -m --color 'fg:64'\
3131
--bind 'q:abort'\
3232
--bind '?:toggle-preview'\
@@ -45,16 +45,16 @@ function read_and_restore_staged_files() {
4545
while read -r str; do
4646

4747
if [[ ${str:0:1} != "R" ]]; then
48-
local file="${str#"${str:0:3}"}"
48+
local file="${str#"${str:0:3}"}" # remove first 3 characters
4949
restore_staged_file "${file}"
5050
continue
5151
fi
5252

53+
str="${str#"${str:0:3}"}" # remove first 3 characters
5354
__split_str "${str}" " -> "
5455
local oldFile="${RESULT_ARR[0]}"
5556
local newFile="${RESULT_ARR[1]}"
5657

57-
oldFile="${oldFile#"R "}"
5858
restore_staged_file "${oldFile}"
5959
restore_staged_file "${newFile}"
6060
done
@@ -75,4 +75,4 @@ if [[ $# -eq 1 && "$*" == "." ]]; then
7575
exit 0
7676
fi
7777

78-
__print_err "valid input to grestorestaged: \".\""
78+
__print_err "valid input to grestorestaged: \".\""

util/__intend_to_add_untracked_files

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ source "$__CUSTOM_CONSOLE_UTIL"/__trim_double_quotes
66

77
function __intend_to_add_untracked_files() {
88

9+
local untrackedFile=""
910
git status --short | grep "^[?]" | while read -r untrackedFile; do
1011
untrackedFile=${untrackedFile#"?? "}
1112
untrackedFile="$(__trim_double_quotes "${untrackedFile}")"

0 commit comments

Comments
 (0)