Merge branch 'js/maint-reflog-beyond-horizon'
* js/maint-reflog-beyond-horizon:
  t1503: fix broken test_must_fail calls
  rev-parse: tests git rev-parse --verify master@{n}, for various n
  sha1_name.c: use warning in preference to fprintf(stderr
  rev-parse: exit with non-zero status if ref@{n} is not valid.
			
			
				maint
			
			
		
						commit
						306d7e5556
					
				
							
								
								
									
										18
									
								
								sha1_name.c
								
								
								
								
							
							
						
						
									
										18
									
								
								sha1_name.c
								
								
								
								
							|  | @ -342,7 +342,7 @@ static int get_sha1_1(const char *name, int len, unsigned char *sha1); | ||||||
|  |  | ||||||
| static int get_sha1_basic(const char *str, int len, unsigned char *sha1) | static int get_sha1_basic(const char *str, int len, unsigned char *sha1) | ||||||
| { | { | ||||||
| 	static const char *warning = "warning: refname '%.*s' is ambiguous.\n"; | 	static const char *warn_msg = "refname '%.*s' is ambiguous."; | ||||||
| 	char *real_ref = NULL; | 	char *real_ref = NULL; | ||||||
| 	int refs_found = 0; | 	int refs_found = 0; | ||||||
| 	int at, reflog_len; | 	int at, reflog_len; | ||||||
|  | @ -390,7 +390,7 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1) | ||||||
| 		return -1; | 		return -1; | ||||||
|  |  | ||||||
| 	if (warn_ambiguous_refs && refs_found > 1) | 	if (warn_ambiguous_refs && refs_found > 1) | ||||||
| 		fprintf(stderr, warning, len, str); | 		warning(warn_msg, len, str); | ||||||
|  |  | ||||||
| 	if (reflog_len) { | 	if (reflog_len) { | ||||||
| 		int nth, i; | 		int nth, i; | ||||||
|  | @ -426,14 +426,14 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1) | ||||||
| 		if (read_ref_at(real_ref, at_time, nth, sha1, NULL, | 		if (read_ref_at(real_ref, at_time, nth, sha1, NULL, | ||||||
| 				&co_time, &co_tz, &co_cnt)) { | 				&co_time, &co_tz, &co_cnt)) { | ||||||
| 			if (at_time) | 			if (at_time) | ||||||
| 				fprintf(stderr, | 				warning("Log for '%.*s' only goes " | ||||||
| 					"warning: Log for '%.*s' only goes " | 					"back to %s.", len, str, | ||||||
| 					"back to %s.\n", len, str, |  | ||||||
| 					show_date(co_time, co_tz, DATE_RFC2822)); | 					show_date(co_time, co_tz, DATE_RFC2822)); | ||||||
| 			else | 			else { | ||||||
| 				fprintf(stderr, | 				free(real_ref); | ||||||
| 					"warning: Log for '%.*s' only has " | 				die("Log for '%.*s' only has %d entries.", | ||||||
| 					"%d entries.\n", len, str, co_cnt); | 				    len, str, co_cnt); | ||||||
|  | 			} | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  |  | ||||||
|  | @ -104,4 +104,15 @@ test_expect_success 'use --default' ' | ||||||
| 	test_must_fail git rev-parse --verify --default bar | 	test_must_fail git rev-parse --verify --default bar | ||||||
| ' | ' | ||||||
|  |  | ||||||
|  | test_expect_success 'master@{n} for various n' ' | ||||||
|  | 	N=$(git reflog | wc -l) && | ||||||
|  | 	Nm1=$((N-1)) && | ||||||
|  | 	Np1=$((N+1)) && | ||||||
|  | 	git rev-parse --verify master@{0} && | ||||||
|  | 	git rev-parse --verify master@{1} && | ||||||
|  | 	git rev-parse --verify master@{$Nm1} && | ||||||
|  | 	test_must_fail git rev-parse --verify master@{$N} && | ||||||
|  | 	test_must_fail git rev-parse --verify master@{$Np1} | ||||||
|  | ' | ||||||
|  |  | ||||||
| test_done | test_done | ||||||
|  |  | ||||||
|  | @ -66,4 +66,13 @@ test_expect_success 'incorrect file in :path and :N:path' ' | ||||||
| 	grep "fatal: Path '"'"'disk-only.txt'"'"' exists on disk, but not in the index." error | 	grep "fatal: Path '"'"'disk-only.txt'"'"' exists on disk, but not in the index." error | ||||||
| ' | ' | ||||||
|  |  | ||||||
|  | test_expect_success 'invalid @{n} reference' ' | ||||||
|  | 	test_must_fail git rev-parse master@{99999} >output 2>error && | ||||||
|  | 	test -z "$(cat output)" && | ||||||
|  | 	grep "fatal: Log for [^ ]* only has [0-9][0-9]* entries." error  && | ||||||
|  | 	test_must_fail git rev-parse --verify master@{99999} >output 2>error && | ||||||
|  | 	test -z "$(cat output)" && | ||||||
|  | 	grep "fatal: Log for [^ ]* only has [0-9][0-9]* entries." error | ||||||
|  | ' | ||||||
|  |  | ||||||
| test_done | test_done | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	 Junio C Hamano
						Junio C Hamano