Skip to content

Commit 439d3a1

Browse files
bk2204gitster
authored andcommitted
http-fetch: set up git directory before parsing pack hashes
In dd4b732 ("upload-pack: send part of packfile response as uri", 2020-06-10), the git http-fetch code learned how to take ac --packfile option. This option takes an argument, which is the name of a packfile hash, and parses it using parse_oid_hex. It does so before calling setup_git_directory. However, in a SHA-256 repository this fails to work, since we have not set the hash algorithm in use and parse_oid_hex fails as a consequence. To ensure that we can parse packfile hashes of the right length, let's set up the git directory before we start parsing arguments. Since we still want to allow the invocation of -h to print the help when we're not in a repository, gracefully handle us being outside of one and produce an error after argument parsing has finished. Signed-off-by: brian m. carlson <[email protected]> Reviewed-by: Eric Sunshine <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6c2adf8 commit 439d3a1

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

http-fetch.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,11 @@ int cmd_main(int argc, const char **argv)
8484
int get_verbosely = 0;
8585
int get_recover = 0;
8686
int packfile = 0;
87+
int nongit;
8788
struct object_id packfile_hash;
8889

90+
setup_git_directory_gently(&nongit);
91+
8992
while (arg < argc && argv[arg][0] == '-') {
9093
const char *p;
9194

@@ -115,7 +118,8 @@ int cmd_main(int argc, const char **argv)
115118
if (argc != arg + 2 - (commits_on_stdin || packfile))
116119
usage(http_fetch_usage);
117120

118-
setup_git_directory();
121+
if (nongit)
122+
die(_("not a git repository"));
119123

120124
git_config(git_default_config, NULL);
121125

0 commit comments

Comments
 (0)