Skip to content

Commit ff86bdd

Browse files
committed
Merge branch 'maint'
* maint: add-interactive: fix deletion of non-empty files pull: clarify advice for the unconfigured error case
2 parents ca83dc5 + 5c30b8f commit ff86bdd

File tree

3 files changed

+58
-16
lines changed

3 files changed

+58
-16
lines changed

git-add--interactive.perl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1216,7 +1216,11 @@ sub patch_update_file {
12161216
if (@{$mode->{TEXT}}) {
12171217
unshift @hunk, $mode;
12181218
}
1219-
if (@{$deletion->{TEXT}} && !@hunk) {
1219+
if (@{$deletion->{TEXT}}) {
1220+
foreach my $hunk (@hunk) {
1221+
push @{$deletion->{TEXT}}, @{$hunk->{TEXT}};
1222+
push @{$deletion->{DISPLAY}}, @{$hunk->{DISPLAY}};
1223+
}
12201224
@hunk = ($deletion);
12211225
}
12221226

git-pull.sh

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -91,45 +91,63 @@ error_on_no_merge_candidates () {
9191
esac
9292
done
9393

94+
if test true = "$rebase"
95+
then
96+
op_type=rebase
97+
op_prep=against
98+
else
99+
op_type=merge
100+
op_prep=with
101+
fi
102+
94103
curr_branch=${curr_branch#refs/heads/}
95104
upstream=$(git config "branch.$curr_branch.merge")
96105
remote=$(git config "branch.$curr_branch.remote")
97106

98107
if [ $# -gt 1 ]; then
99-
echo "There are no candidates for merging in the refs that you just fetched."
108+
if [ "$rebase" = true ]; then
109+
printf "There is no candidate for rebasing against "
110+
else
111+
printf "There are no candidates for merging "
112+
fi
113+
echo "among the refs that you just fetched."
100114
echo "Generally this means that you provided a wildcard refspec which had no"
101115
echo "matches on the remote end."
102116
elif [ $# -gt 0 ] && [ "$1" != "$remote" ]; then
103117
echo "You asked to pull from the remote '$1', but did not specify"
104-
echo "a branch to merge. Because this is not the default configured remote"
118+
echo "a branch. Because this is not the default configured remote"
105119
echo "for your current branch, you must specify a branch on the command line."
106120
elif [ -z "$curr_branch" ]; then
107121
echo "You are not currently on a branch, so I cannot use any"
108122
echo "'branch.<branchname>.merge' in your configuration file."
109-
echo "Please specify which branch you want to merge on the command"
123+
echo "Please specify which remote branch you want to use on the command"
110124
echo "line and try again (e.g. 'git pull <repository> <refspec>')."
111125
echo "See git-pull(1) for details."
112126
elif [ -z "$upstream" ]; then
113127
echo "You asked me to pull without telling me which branch you"
114-
echo "want to merge with, and 'branch.${curr_branch}.merge' in"
115-
echo "your configuration file does not tell me either. Please"
116-
echo "specify which branch you want to merge on the command line and"
128+
echo "want to $op_type $op_prep, and 'branch.${curr_branch}.merge' in"
129+
echo "your configuration file does not tell me, either. Please"
130+
echo "specify which branch you want to use on the command line and"
117131
echo "try again (e.g. 'git pull <repository> <refspec>')."
118132
echo "See git-pull(1) for details."
119133
echo
120-
echo "If you often merge with the same branch, you may want to"
121-
echo "configure the following variables in your configuration"
122-
echo "file:"
134+
echo "If you often $op_type $op_prep the same branch, you may want to"
135+
echo "use something like the following in your configuration file:"
136+
echo
137+
echo " [branch \"${curr_branch}\"]"
138+
echo " remote = <nickname>"
139+
echo " merge = <remote-ref>"
140+
test rebase = "$op_type" &&
141+
echo " rebase = true"
123142
echo
124-
echo " branch.${curr_branch}.remote = <nickname>"
125-
echo " branch.${curr_branch}.merge = <remote-ref>"
126-
echo " remote.<nickname>.url = <url>"
127-
echo " remote.<nickname>.fetch = <refspec>"
143+
echo " [remote \"<nickname>\"]"
144+
echo " url = <url>"
145+
echo " fetch = <refspec>"
128146
echo
129147
echo "See git-config(1) for details."
130148
else
131-
echo "Your configuration specifies to merge the ref '${upstream#refs/heads/}' from the"
132-
echo "remote, but no such ref was fetched."
149+
echo "Your configuration specifies to $op_type $op_prep the ref '${upstream#refs/heads/}'"
150+
echo "from the remote, but no such ref was fetched."
133151
fi
134152
exit 1
135153
}

t/t3701-add-interactive.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,26 @@ test_expect_success 'add first line works' '
228228
test_cmp expected diff
229229
'
230230

231+
cat >expected <<EOF
232+
diff --git a/non-empty b/non-empty
233+
deleted file mode 100644
234+
index d95f3ad..0000000
235+
--- a/non-empty
236+
+++ /dev/null
237+
@@ -1 +0,0 @@
238+
-content
239+
EOF
240+
test_expect_success 'deleting a non-empty file' '
241+
git reset --hard &&
242+
echo content >non-empty &&
243+
git add non-empty &&
244+
git commit -m non-empty &&
245+
rm non-empty &&
246+
echo y | git add -p non-empty &&
247+
git diff --cached >diff &&
248+
test_cmp expected diff
249+
'
250+
231251
cat >expected <<EOF
232252
diff --git a/empty b/empty
233253
deleted file mode 100644

0 commit comments

Comments
 (0)