git-mv: shrink usage, no usage on error
Small fixes to be consistent with other git scripts: - usage message is only about options and arguments - on error, exit(1) without the usage message Additionally, "beautifies" output with -n a little bit Signed-off-by: Josef Weidendorfer <Josef.Weidendorfer@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>
Josef Weidendorfer committed
Nov 27, 2005 at 21:58 UTC
3ae64dff6894adc995c913aaf7fe2d65c78c3529
1 file changed
+19
-27
git-mv.perl
+19
-27
@@ -13,22 +13,8 @@ use Getopt::Std;
13
14
sub usage() {
15
print <<EOT;
16
-$0 [-f] [-n] <source> <dest>
17
-$0 [-f] [-k] [-n] <source> ... <dest directory>
18
-
19
-In the first form, source must exist and be either a file,
20
-symlink or directory, dest must not exist. It renames source to dest.
21
-In the second form, the last argument has to be an existing
22
-directory; the given sources will be moved into this directory.
23
-
24
-Updates the git cache to reflect the change.
25
-Use "git commit" to make the change permanently.
26
-
27
-Options:
28
- -f Force renaming/moving, even if target exists
29
- -k Continue on error by skipping
30
- not-existing or not revision-controlled source
31
- -n Do nothing; show what would happen
16
+$0 [-f] [-n] <source> <destination>
17
+$0 [-f] [-n] [-k] <source> ... <destination directory>
18
EOT
19
exit(1);
20
}
@@ -38,8 +24,8 @@ my $GIT_DIR = $ENV{'GIT_DIR'} || ".git";
24
25
unless ( -d $GIT_DIR && -d $GIT_DIR . "/objects" &&
26
-d $GIT_DIR . "/objects/" && -d $GIT_DIR . "/refs") {
41
- print "Git repository not found.";
42
- usage();
27
+ print "Error: git repository not found.";
28
+ exit(1);
29
}
30
31
@@ -70,7 +56,7 @@ else {
56
print "Error: moving to directory '"
57
. $ARGV[$argCount-1]
58
. "' not possible; not exisiting\n";
73
- usage;
59
+ exit(1);
60
}
61
@srcArgs = ($ARGV[0]);
62
@dstArgs = ($ARGV[1]);
@@ -148,7 +134,7 @@ while(scalar @srcArgs > 0) {
134
next;
135
}
136
print "Error: $bad\n";
151
- usage();
137
+ exit(1);
138
}
139
push @srcs, $src;
140
push @dsts, $dst;
@@ -187,33 +173,39 @@ while(scalar @srcs > 0) {
173
}
174
175
if ($opt_n) {
176
+ if (@changedfiles) {
177
print "Changed : ". join(", ", @changedfiles) ."\n";
178
+ }
179
+ if (@addedfiles) {
180
print "Adding : ". join(", ", @addedfiles) ."\n";
181
+ }
182
+ if (@deletedfiles) {
183
print "Deleting : ". join(", ", @deletedfiles) ."\n";
193
- exit(1);
184
+ }
185
}
195
-
196
-if (@changedfiles) {
186
+else {
187
+ if (@changedfiles) {
188
open(H, "| git-update-index -z --stdin")
189
or die "git-update-index failed to update changed files with code $!\n";
190
foreach my $fileName (@changedfiles) {
191
print H "$fileName\0";
192
}
193
close(H);
203
-}
204
-if (@addedfiles) {
194
+ }
195
+ if (@addedfiles) {
196
open(H, "| git-update-index --add -z --stdin")
197
or die "git-update-index failed to add new names with code $!\n";
198
foreach my $fileName (@addedfiles) {
199
print H "$fileName\0";
200
}
201
close(H);
211
-}
212
-if (@deletedfiles) {
202
+ }
203
+ if (@deletedfiles) {
204
open(H, "| git-update-index --remove -z --stdin")
205
or die "git-update-index failed to remove old names with code $!\n";
206
foreach my $fileName (@deletedfiles) {
207
print H "$fileName\0";
208
}
209
close(H);
210
+ }
211
}