Commit e31abbf21f99a7312bdfd392f33ace285feadfe5

Stefan Sperling 2020-03-22T14:21:06

add -c option to 'got ref' which now expects just one argument after options

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
diff --git a/got/got.1 b/got/got.1
index 62fe17b..59cc0bc 100644
--- a/got/got.1
+++ b/got/got.1
@@ -821,20 +821,15 @@ Recurse into sub-directories in the repository.
 .It Cm tr
 Short alias for
 .Cm tree .
-.It Cm ref Oo Fl r Ar repository-path Oc Oo Fl l Oc Oo Fl d Ar name Oc Oo Fl s Oc Op Ar name Ar target
+.It Cm ref Oo Fl r Ar repository-path Oc Oo Fl l Oc Oo Fl c Ar object Oc Oo Fl s Ar reference Oc Oo Fl d Oc Op Ar name
 Manage references in a repository.
 .Pp
-If no options are passed, expect two arguments and attempt to create,
-or update, the reference with the given
-.Ar name ,
-and make it point at the given
-.Ar target .
-The name must be an absolute reference name, i.e. it must begin with
+References may be listed, created, deleted, and changed.
+When creating, deleting, or changing a reference the specified
+.Ar name
+must be an absolute reference name, i.e. it must begin with
 .Dq refs/ .
-The target may be an object ID SHA1 hash or an existing reference which
-will be resolved to an object ID.
-An abbreviated hash argument will be expanded to a full SHA1 hash
-automatically, provided the abbreviation is unique.
+.Pp
 .Pp
 The options for
 .Cm got ref
@@ -849,14 +844,37 @@ If this directory is a
 work tree, use the repository path associated with this work tree.
 .It Fl l
 List all existing references in the repository.
-.It Fl d Ar name
-Delete the reference with the specified name from the repository.
-.It Fl s
-Create a symbolic reference pointing at the specified
-.Ar target ,
-which must be an existing reference.
+Cannot be used together with any other options except
+.Fl r .
+.It Fl c Ar object
+Create a reference or change an existing reference.
+The reference with the specified
+.Ar name
+will point at the specified
+.Ar object.
+The expected
+.Ar object
+argument is a ID SHA1 hash or an existing reference or tag name which will
+be resolved to the ID of a corresponding commit, tree, tag, or blob object.
+Cannot be used together with any other options except
+.Fl r .
+.It Fl s Ar reference
+Create a symbolic reference, or change an existing symbolic reference.
+The symbolic reference with the specified
+.Ar name
+will point at the specified
+.Ar reference
+which must already exist in the repository.
 Care should be taken not to create loops between references when
 this option is used.
+Cannot be used together with any other options except
+.Fl r .
+.It Fl d
+Delete the reference with the specified
+.Ar name
+from the repository.
+Cannot be used together with any other options except
+.Fl r .
 .El
 .It Cm branch Oo Fl c Ar commit Oc Oo Fl r Ar repository-path Oc Oo Fl l Oc Oo Fl d Ar name Oc Oo Fl n Oc Op Ar name
 Create, list, or delete branches.
diff --git a/got/got.c b/got/got.c
index cebadef..b27ba04 100644
--- a/got/got.c
+++ b/got/got.c
@@ -4175,7 +4175,8 @@ __dead static void
 usage_ref(void)
 {
 	fprintf(stderr,
-	    "usage: %s ref [-r repository] -l | -d name | [-s] name target\n",
+	    "usage: %s ref [-r repository] [-l] [-c object] [-s reference] "
+	        "[-d] [name]\n",
 	    getprogname());
 	exit(1);
 }
@@ -4302,14 +4303,16 @@ cmd_ref(int argc, char *argv[])
 	struct got_repository *repo = NULL;
 	struct got_worktree *worktree = NULL;
 	char *cwd = NULL, *repo_path = NULL;
-	int ch, do_list = 0, create_symref = 0;
-	const char *delref = NULL;
+	int ch, do_list = 0, do_delete = 0;
+	const char *refname = NULL, *obj_arg = NULL, *symref_target= NULL;
 
-	/* TODO: Add -s option for adding symbolic references. */
-	while ((ch = getopt(argc, argv, "d:r:ls")) != -1) {
+	while ((ch = getopt(argc, argv, "c:dr:ls:")) != -1) {
 		switch (ch) {
+		case 'c':
+			obj_arg = optarg;
+			break;
 		case 'd':
-			delref = optarg;
+			do_delete = 1;
 			break;
 		case 'r':
 			repo_path = realpath(optarg, NULL);
@@ -4322,7 +4325,7 @@ cmd_ref(int argc, char *argv[])
 			do_list = 1;
 			break;
 		case 's':
-			create_symref = 1;
+			symref_target = optarg;
 			break;
 		default:
 			usage_ref();
@@ -4330,20 +4333,30 @@ cmd_ref(int argc, char *argv[])
 		}
 	}
 
-	if (do_list && delref)
-		errx(1, "-l and -d options are mutually exclusive\n");
+	if (obj_arg && do_list)
+		errx(1, "-c and -l options are mutually exclusive\n");
+	if (obj_arg && do_delete)
+		errx(1, "-c and -d options are mutually exclusive\n");
+	if (obj_arg && symref_target)
+		errx(1, "-c and -s options are mutually exclusive\n");
+	if (symref_target && do_delete)
+		errx(1, "-s and -d options are mutually exclusive\n");
+	if (symref_target && do_list)
+		errx(1, "-s and -l options are mutually exclusive\n");
+	if (do_delete && do_list)
+		errx(1, "-d and -l options are mutually exclusive\n");
 
 	argc -= optind;
 	argv += optind;
 
-	if (do_list || delref) {
-		if (create_symref)
-			errx(1, "-s option cannot be used together with the "
-			    "-l or -d options");
+	if (do_list) {
 		if (argc > 0)
 			usage_ref();
-	} else if (argc != 2)
-		usage_ref();
+	} else {
+		if (argc != 1)
+			usage_ref();
+		refname = argv[0];
+	}
 
 #ifndef PROFILE
 	if (do_list) {
@@ -4395,12 +4408,15 @@ cmd_ref(int argc, char *argv[])
 
 	if (do_list)
 		error = list_refs(repo);
-	else if (delref)
-		error = delete_ref(repo, delref);
-	else if (create_symref)
-		error = add_symref(repo, argv[0], argv[1]);
-	else
-		error = add_ref(repo, argv[0], argv[1]);
+	else if (do_delete)
+		error = delete_ref(repo, refname);
+	else if (symref_target)
+		error = add_symref(repo, refname, symref_target);
+	else {
+		if (obj_arg == NULL)
+			usage_ref();
+		error = add_ref(repo, refname, obj_arg);
+	}
 done:
 	if (repo)
 		got_repo_close(repo);
diff --git a/regress/cmdline/clone.sh b/regress/cmdline/clone.sh
index f3a8329..446d7b7 100755
--- a/regress/cmdline/clone.sh
+++ b/regress/cmdline/clone.sh
@@ -93,7 +93,7 @@ function test_clone_list {
 	local commit_id=`git_show_head $testroot/repo`
 
 	got branch -r $testroot/repo -c $commit_id foo
-	got ref -r $testroot/repo refs/hoo/boo/zoo $commit_id
+	got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
 	got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
 
 	got clone -l $testurl/repo > $testroot/stdout 2>$testroot/stderr
@@ -121,7 +121,7 @@ function test_clone_branch {
 	local commit_id=`git_show_head $testroot/repo`
 
 	got branch -r $testroot/repo -c $commit_id foo
-	got ref -r $testroot/repo refs/hoo/boo/zoo $commit_id
+	got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
 	got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
 	local tag_id=`got ref -r $testroot/repo -l \
 		| grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
@@ -157,7 +157,7 @@ function test_clone_all {
 	local commit_id=`git_show_head $testroot/repo`
 
 	got branch -r $testroot/repo -c $commit_id foo
-	got ref -r $testroot/repo refs/hoo/boo/zoo $commit_id
+	got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
 	got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
 	local tag_id=`got ref -r $testroot/repo -l \
 		| grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
@@ -195,7 +195,7 @@ function test_clone_mirror {
 	local commit_id=`git_show_head $testroot/repo`
 
 	got branch -r $testroot/repo -c $commit_id foo
-	got ref -r $testroot/repo refs/hoo/boo/zoo $commit_id
+	got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
 	got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
 	local tag_id=`got ref -r $testroot/repo -l \
 		| grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
@@ -230,7 +230,7 @@ function test_clone_mirror_all {
 	local commit_id=`git_show_head $testroot/repo`
 
 	got branch -r $testroot/repo -c $commit_id foo
-	got ref -r $testroot/repo refs/hoo/boo/zoo $commit_id
+	got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
 	got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
 	local tag_id=`got ref -r $testroot/repo -l \
 		| grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
@@ -265,7 +265,7 @@ function test_clone_reference {
 	local commit_id=`git_show_head $testroot/repo`
 
 	got branch -r $testroot/repo -c $commit_id foo
-	got ref -r $testroot/repo refs/hoo/boo/zoo $commit_id
+	got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
 	got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
 	local tag_id=`got ref -r $testroot/repo -l \
 		| grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
@@ -302,7 +302,7 @@ function test_clone_branch_and_reference {
 	local commit_id=`git_show_head $testroot/repo`
 
 	got branch -r $testroot/repo -c $commit_id foo
-	got ref -r $testroot/repo refs/hoo/boo/zoo $commit_id
+	got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
 	got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
 	local tag_id=`got ref -r $testroot/repo -l \
 		| grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
@@ -339,7 +339,7 @@ function test_clone_reference_mirror {
 	local commit_id=`git_show_head $testroot/repo`
 
 	got branch -r $testroot/repo -c $commit_id foo
-	got ref -r $testroot/repo refs/hoo/boo/zoo $commit_id
+	got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
 	got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
 	local tag_id=`got ref -r $testroot/repo -l \
 		| grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
diff --git a/regress/cmdline/commit.sh b/regress/cmdline/commit.sh
index fbf48ee..a131681 100755
--- a/regress/cmdline/commit.sh
+++ b/regress/cmdline/commit.sh
@@ -499,7 +499,7 @@ function test_commit_selected_paths {
 function test_commit_outside_refs_heads {
 	local testroot=`test_init commit_outside_refs_heads`
 
-	got ref -r $testroot/repo refs/remotes/origin/master master
+	got ref -r $testroot/repo -c master refs/remotes/origin/master
 
 	got checkout -b refs/remotes/origin/master \
 	    $testroot/repo $testroot/wt > /dev/null
diff --git a/regress/cmdline/fetch.sh b/regress/cmdline/fetch.sh
index b59b39e..fb811d1 100755
--- a/regress/cmdline/fetch.sh
+++ b/regress/cmdline/fetch.sh
@@ -123,7 +123,7 @@ function test_fetch_list {
 	local commit_id=`git_show_head $testroot/repo`
 
 	got branch -r $testroot/repo -c $commit_id foo
-	got ref -r $testroot/repo refs/hoo/boo/zoo $commit_id
+	got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
 	got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
 
 	got clone -q $testurl/repo $testroot/repo-clone
@@ -168,7 +168,7 @@ function test_fetch_branch {
 	fi
 
 	got branch -r $testroot/repo -c $commit_id foo
-	got ref -r $testroot/repo refs/hoo/boo/zoo $commit_id
+	got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
 	got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
 	local tag_id=`got ref -r $testroot/repo -l \
 		| grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
@@ -271,7 +271,7 @@ function test_fetch_all {
 	fi
 
 	got branch -r $testroot/repo -c $commit_id foo
-	got ref -r $testroot/repo refs/hoo/boo/zoo $commit_id
+	got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
 	got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
 	local tag_id=`got ref -r $testroot/repo -l \
 		| grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
@@ -337,7 +337,7 @@ function test_fetch_empty_packfile {
 	fi
 
 	got branch -r $testroot/repo -c $commit_id foo
-	got ref -r $testroot/repo refs/hoo/boo/zoo $commit_id
+	got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
 
 	got ref -l -r $testroot/repo-clone > $testroot/stdout
 
@@ -390,7 +390,7 @@ function test_fetch_delete_branch {
 
 
 	got branch -r $testroot/repo -c $commit_id foo
-	got ref -r $testroot/repo refs/hoo/boo/zoo $commit_id
+	got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
 	got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
 	local tag_id=`got ref -r $testroot/repo -l \
 		| grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
@@ -497,7 +497,7 @@ function test_fetch_update_tag {
 
 
 	got branch -r $testroot/repo -c $commit_id foo
-	got ref -r $testroot/repo refs/hoo/boo/zoo $commit_id
+	got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
 	got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
 	local tag_id=`got ref -r $testroot/repo -l \
 		| grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
@@ -656,7 +656,7 @@ function test_fetch_reference {
 	fi
 
 	got branch -r $testroot/repo -c $commit_id foo
-	got ref -r $testroot/repo refs/hoo/boo/zoo $commit_id
+	got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
 	got tag -r $testroot/repo -c $commit_id -m tag "1.0" >/dev/null
 	local tag_id=`got ref -r $testroot/repo -l \
 		| grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2`
@@ -741,8 +741,8 @@ function test_fetch_replace_symref {
 		return 1
 	fi
 
-	got ref -r $testroot/repo refs/hoo/boo/zoo $commit_id
-	got ref -r $testroot/repo-clone -s refs/hoo/boo/zoo refs/heads/master
+	got ref -r $testroot/repo -c $commit_id refs/hoo/boo/zoo
+	got ref -r $testroot/repo-clone -s refs/heads/master refs/hoo/boo/zoo
 
 	got ref -l -r $testroot/repo-clone > $testroot/stdout
 
diff --git a/regress/cmdline/histedit.sh b/regress/cmdline/histedit.sh
index d858406..a2bae29 100755
--- a/regress/cmdline/histedit.sh
+++ b/regress/cmdline/histedit.sh
@@ -1086,7 +1086,7 @@ function test_histedit_outside_refs_heads {
 	fi
 	local commit2=`git_show_head $testroot/repo`
 
-	got ref -r $testroot/repo refs/remotes/origin/master master
+	got ref -r $testroot/repo -c master refs/remotes/origin/master
 	ret="$?"
 	if [ "$ret" != "0" ]; then
 		echo "got ref failed unexpectedly" >&2
diff --git a/regress/cmdline/rebase.sh b/regress/cmdline/rebase.sh
index 262922a..7423d96 100755
--- a/regress/cmdline/rebase.sh
+++ b/regress/cmdline/rebase.sh
@@ -819,9 +819,8 @@ function test_rebase_forward {
 	# commit ffcffcd102cf1af6572fbdbb4cf07a0f1fd2d840 (master)
 	# commit 87a6a8a2263a15b61c016ff1720b24741d455eb5
 	(cd $testroot/repo && got ref -d master)
-	(cd $testroot/repo && got ref refs/heads/master $commit1)
-	(cd $testroot/repo && got ref refs/remotes/origin/master $commit2)
-
+	(cd $testroot/repo && got ref -c $commit1 refs/heads/master)
+	(cd $testroot/repo && got ref -c $commit2 refs/remotes/origin/master)
 
 	(cd $testroot/wt && got up -b origin/master > /dev/null)
 
diff --git a/regress/cmdline/ref.sh b/regress/cmdline/ref.sh
index 50b3132..9473644 100755
--- a/regress/cmdline/ref.sh
+++ b/regress/cmdline/ref.sh
@@ -20,8 +20,8 @@ function test_ref_create {
 	local testroot=`test_init ref_create`
 	local commit_id=`git_show_head $testroot/repo`
 
-	# Create a ref based on a commit ID
-	got ref -r $testroot/repo refs/heads/commitref $commit_id
+	# Create a ref pointing at a commit ID
+	got ref -r $testroot/repo -c $commit_id refs/heads/commitref
 	ret="$?"
 	if [ "$ret" != "0" ]; then
 		echo "got ref command failed unexpectedly"
@@ -30,7 +30,7 @@ function test_ref_create {
 	fi
 
 	# Create a ref based on repository's HEAD reference
-	got ref -r $testroot/repo refs/heads/newref HEAD
+	got ref -r $testroot/repo -c HEAD refs/heads/newref
 	ret="$?"
 	if [ "$ret" != "0" ]; then
 		echo "got ref command failed unexpectedly"
@@ -57,7 +57,7 @@ function test_ref_create {
 	fi
 
 	# Create a head ref based on another specific ref
-	(cd $testroot/wt && got ref refs/heads/anotherref refs/heads/master)
+	(cd $testroot/wt && got ref -c refs/heads/master refs/heads/anotherref)
 	ret="$?"
 	if [ "$ret" != "0" ]; then
 		test_done "$testroot" "$ret"
@@ -72,7 +72,7 @@ function test_ref_create {
 	fi
 
 	# Create a symbolic ref
-	(cd $testroot/wt && got ref -s refs/heads/symbolicref refs/heads/master)
+	(cd $testroot/wt && got ref -s refs/heads/master refs/heads/symbolicref)
 	ret="$?"
 	if [ "$ret" != "0" ]; then
 		test_done "$testroot" "$ret"
@@ -88,7 +88,7 @@ function test_ref_create {
 	fi
 
 	# Attempt to create a symbolic ref pointing at a non-reference
-	(cd $testroot/wt && got ref -s refs/heads/symbolicref $commit_id \
+	(cd $testroot/wt && got ref -s $commit_id refs/heads/symbolicref \
 		2> $testroot/stderr)
 	ret="$?"
 	if [ "$ret" == "0" ]; then
@@ -106,8 +106,45 @@ function test_ref_create {
 		return 1
 	fi
 
+	# Attempt to create a reference without specifying a name
+	(cd $testroot/wt && got ref -c $commit_id 2> $testroot/stderr)
+	ret="$?"
+	if [ "$ret" == "0" ]; then
+		echo "git ref command succeeded unexpectedly"
+		test_done "$testroot" "1"
+		return 1
+	fi
+
+	grep -q '^usage: got ref' $testroot/stderr
+	ret="$?"
+	if [ "$ret" != "0" ]; then
+		echo "unexpected usage error message: " >&2
+		cat $testroot/stderr >&2
+		test_done "$testroot" "$ret"
+		return 1
+	fi
+
+	# Attempt to create a symbolic reference without specifying a name
+	(cd $testroot/wt && got ref -s refs/heads/symbolicref \
+		2> $testroot/stderr)
+	ret="$?"
+	if [ "$ret" == "0" ]; then
+		echo "git ref command succeeded unexpectedly"
+		test_done "$testroot" "1"
+		return 1
+	fi
+
+	grep -q '^usage: got ref' $testroot/stderr
+	ret="$?"
+	if [ "$ret" != "0" ]; then
+		echo "unexpected usage error message: " >&2
+		cat $testroot/stderr >&2
+		test_done "$testroot" "$ret"
+		return 1
+	fi
+
 	# Change HEAD
-	got ref -r $testroot/repo -s HEAD refs/heads/newref
+	got ref -r $testroot/repo -s refs/heads/newref HEAD
 	ret="$?"
 	if [ "$ret" != "0" ]; then
 		echo "got ref command failed unexpectedly"
@@ -156,7 +193,7 @@ function test_ref_delete {
 	local commit_id=`git_show_head $testroot/repo`
 
 	for b in ref1 ref2 ref3; do
-		got ref -r $testroot/repo refs/heads/$b refs/heads/master
+		got ref -r $testroot/repo -c refs/heads/master refs/heads/$b
 		ret="$?"
 		if [ "$ret" != "0" ]; then
 			echo "got ref command failed unexpectedly"
@@ -165,7 +202,7 @@ function test_ref_delete {
 		fi
 	done
 
-	got ref -d refs/heads/ref2 -r $testroot/repo > $testroot/stdout
+	got ref -d -r $testroot/repo refs/heads/ref2 > $testroot/stdout
 	ret="$?"
 	if [ "$ret" != "0" ]; then
 		echo "got ref command failed unexpectedly"
@@ -186,7 +223,7 @@ function test_ref_delete {
 		return 1
 	fi
 
-	got ref -d refs/heads/bogus_ref_name -r $testroot/repo \
+	got ref -r $testroot/repo -d refs/heads/bogus_ref_name \
 		> $testroot/stdout 2> $testroot/stderr
 	ret="$?"
 	if [ "$ret" == "0" ]; then