From 43df4f86e035056605ceb757029181d7ddee1e7e Mon Sep 17 00:00:00 2001 From: Dmitry Potapov Date: Sun, 3 Aug 2008 08:39:16 +0400 Subject: [PATCH 1/6] teach index_fd to work with pipes index_fd can now work with file descriptors that are not normal files but any readable file. If the given file descriptor is a regular file then mmap() is used; for other files, strbuf_read is used. The path parameter, which has been used as hint for filters, can be NULL now to indicate that the file should be hashed literally without any filter. The index_pipe function is removed as redundant. Signed-off-by: Dmitry Potapov Signed-off-by: Junio C Hamano --- cache.h | 1 - hash-object.c | 28 +++++++++++----------- sha1_file.c | 64 ++++++++++++++++++++++----------------------------- 3 files changed, 41 insertions(+), 52 deletions(-) diff --git a/cache.h b/cache.h index 2475de9fa..68ce6e686 100644 --- a/cache.h +++ b/cache.h @@ -391,7 +391,6 @@ extern int ie_modified(const struct index_state *, struct cache_entry *, struct extern int ce_path_match(const struct cache_entry *ce, const char **pathspec); extern int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object, enum object_type type, const char *path); -extern int index_pipe(unsigned char *sha1, int fd, const char *type, int write_object); extern int index_path(unsigned char *sha1, const char *path, struct stat *st, int write_object); extern void fill_stat_cache_info(struct cache_entry *ce, struct stat *st); diff --git a/hash-object.c b/hash-object.c index 46c06a955..7acfae15d 100644 --- a/hash-object.c +++ b/hash-object.c @@ -8,15 +8,12 @@ #include "blob.h" #include "quote.h" -static void hash_object(const char *path, enum object_type type, int write_object) +static void hash_fd(int fd, const char *type, int write_object, const char *path) { - int fd; struct stat st; unsigned char sha1[20]; - fd = open(path, O_RDONLY); - if (fd < 0 || - fstat(fd, &st) < 0 || - index_fd(sha1, fd, &st, write_object, type, path)) + if (fstat(fd, &st) < 0 || + index_fd(sha1, fd, &st, write_object, type_from_string(type), path)) die(write_object ? "Unable to add %s to database" : "Unable to hash %s", path); @@ -24,12 +21,13 @@ static void hash_object(const char *path, enum object_type type, int write_objec maybe_flush_or_die(stdout, "hash to stdout"); } -static void hash_stdin(const char *type, int write_object) +static void hash_object(const char *path, const char *type, int write_object) { - unsigned char sha1[20]; - if (index_pipe(sha1, 0, type, write_object)) - die("Unable to add stdin to database"); - printf("%s\n", sha1_to_hex(sha1)); + int fd; + fd = open(path, O_RDONLY); + if (fd < 0) + die("Cannot open %s", path); + hash_fd(fd, type, write_object, path); } static void hash_stdin_paths(const char *type, int write_objects) @@ -45,7 +43,7 @@ static void hash_stdin_paths(const char *type, int write_objects) die("line is badly quoted"); strbuf_swap(&buf, &nbuf); } - hash_object(buf.buf, type_from_string(type), write_objects); + hash_object(buf.buf, type, write_objects); } strbuf_release(&buf); strbuf_release(&nbuf); @@ -116,13 +114,13 @@ int main(int argc, char **argv) } if (hashstdin) { - hash_stdin(type, write_object); + hash_fd(0, type, write_object, NULL); hashstdin = 0; } if (0 <= prefix_length) arg = prefix_filename(prefix, prefix_length, arg); - hash_object(arg, type_from_string(type), write_object); + hash_object(arg, type, write_object); no_more_flags = 1; } } @@ -131,6 +129,6 @@ int main(int argc, char **argv) hash_stdin_paths(type, write_object); if (hashstdin) - hash_stdin(type, write_object); + hash_fd(0, type, write_object, NULL); return 0; } diff --git a/sha1_file.c b/sha1_file.c index e281c14f0..d453b6664 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -2353,51 +2353,22 @@ int has_sha1_file(const unsigned char *sha1) return has_loose_object(sha1); } -int index_pipe(unsigned char *sha1, int fd, const char *type, int write_object) +static int index_mem(unsigned char *sha1, void *buf, size_t size, + int write_object, enum object_type type, const char *path) { - struct strbuf buf; - int ret; - - strbuf_init(&buf, 0); - if (strbuf_read(&buf, fd, 4096) < 0) { - strbuf_release(&buf); - return -1; - } - - if (!type) - type = blob_type; - if (write_object) - ret = write_sha1_file(buf.buf, buf.len, type, sha1); - else - ret = hash_sha1_file(buf.buf, buf.len, type, sha1); - strbuf_release(&buf); - - return ret; -} - -int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object, - enum object_type type, const char *path) -{ - size_t size = xsize_t(st->st_size); - void *buf = NULL; int ret, re_allocated = 0; - if (size) - buf = xmmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0); - close(fd); - if (!type) type = OBJ_BLOB; /* * Convert blobs to git internal format */ - if ((type == OBJ_BLOB) && S_ISREG(st->st_mode)) { + if ((type == OBJ_BLOB) && path) { struct strbuf nbuf; strbuf_init(&nbuf, 0); if (convert_to_git(path, buf, size, &nbuf, write_object ? safe_crlf : 0)) { - munmap(buf, size); buf = strbuf_detach(&nbuf, &size); re_allocated = 1; } @@ -2407,12 +2378,33 @@ int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object, ret = write_sha1_file(buf, size, typename(type), sha1); else ret = hash_sha1_file(buf, size, typename(type), sha1); - if (re_allocated) { + if (re_allocated) free(buf); - return ret; - } - if (size) + return ret; +} + +int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object, + enum object_type type, const char *path) +{ + int ret; + size_t size = xsize_t(st->st_size); + + if (!S_ISREG(st->st_mode)) { + struct strbuf sbuf; + strbuf_init(&sbuf, 0); + if (strbuf_read(&sbuf, fd, 4096) >= 0) + ret = index_mem(sha1, sbuf.buf, sbuf.len, write_object, + type, path); + else + ret = -1; + strbuf_release(&sbuf); + } else if (size) { + void *buf = xmmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0); + ret = index_mem(sha1, buf, size, write_object, type, path); munmap(buf, size); + } else + ret = index_mem(sha1, NULL, size, write_object, type, path); + close(fd); return ret; } From 81014073f22736e9dcb9370475af44e67234622f Mon Sep 17 00:00:00 2001 From: Dmitry Potapov Date: Sun, 3 Aug 2008 18:36:18 +0400 Subject: [PATCH 2/6] correct argument checking test for git hash-object Because the file name given to stdin did not exist, git hash-object fails to open it and exits with non-zero error code. Thus the test may pass even if there is an error in argument checking. Signed-off-by: Dmitry Potapov Signed-off-by: Junio C Hamano --- t/t1007-hash-object.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/t/t1007-hash-object.sh b/t/t1007-hash-object.sh index 1ec053513..6d505fafe 100755 --- a/t/t1007-hash-object.sh +++ b/t/t1007-hash-object.sh @@ -49,16 +49,16 @@ setup_repo # Argument checking test_expect_success "multiple '--stdin's are rejected" ' - test_must_fail git hash-object --stdin --stdin < example + echo example | test_must_fail git hash-object --stdin --stdin ' test_expect_success "Can't use --stdin and --stdin-paths together" ' - test_must_fail git hash-object --stdin --stdin-paths && - test_must_fail git hash-object --stdin-paths --stdin + echo example | test_must_fail git hash-object --stdin --stdin-paths && + echo example | test_must_fail git hash-object --stdin-paths --stdin ' test_expect_success "Can't pass filenames as arguments with --stdin-paths" ' - test_must_fail git hash-object --stdin-paths hello < example + echo example | test_must_fail git hash-object --stdin-paths hello ' # Behavior From 9ae8e008abf2e05dee59142fae068ae1f9004147 Mon Sep 17 00:00:00 2001 From: Dmitry Potapov Date: Sun, 3 Aug 2008 18:36:19 +0400 Subject: [PATCH 3/6] correct usage help string for git-hash-object The usage string is corrected to make it fit in 80 columns and to make it unequivocal about what options can be used with --stdin-paths. Signed-off-by: Dmitry Potapov Signed-off-by: Junio C Hamano --- Documentation/git-hash-object.txt | 4 +++- hash-object.c | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Documentation/git-hash-object.txt b/Documentation/git-hash-object.txt index ac928e198..a4703ec0d 100644 --- a/Documentation/git-hash-object.txt +++ b/Documentation/git-hash-object.txt @@ -8,7 +8,9 @@ git-hash-object - Compute object ID and optionally creates a blob from a file SYNOPSIS -------- -'git hash-object' [-t ] [-w] [--stdin | --stdin-paths] [--] ... +[verse] +'git hash-object' [-t ] [-w] [--stdin] [--] ... +'git hash-object' [-t ] [-w] --stdin-paths < DESCRIPTION ----------- diff --git a/hash-object.c b/hash-object.c index 7acfae15d..bb7c5dc6e 100644 --- a/hash-object.c +++ b/hash-object.c @@ -50,7 +50,8 @@ static void hash_stdin_paths(const char *type, int write_objects) } static const char hash_object_usage[] = -"git hash-object [ [-t ] [-w] [--stdin] ... | --stdin-paths < ]"; +"git hash-object [-t ] [-w] [--stdin] [--] ...\n" +" or: git hash-object --stdin-paths < "; int main(int argc, char **argv) { From 548601adcc638d96486e0f2a3dd399d4ca215eca Mon Sep 17 00:00:00 2001 From: Dmitry Potapov Date: Sun, 3 Aug 2008 18:36:20 +0400 Subject: [PATCH 4/6] use parse_options() in git hash-object Signed-off-by: Dmitry Potapov Signed-off-by: Junio C Hamano --- hash-object.c | 122 ++++++++++++++++++++++---------------------------- 1 file changed, 53 insertions(+), 69 deletions(-) diff --git a/hash-object.c b/hash-object.c index bb7c5dc6e..489e8369d 100644 --- a/hash-object.c +++ b/hash-object.c @@ -7,6 +7,7 @@ #include "cache.h" #include "blob.h" #include "quote.h" +#include "parse-options.h" static void hash_fd(int fd, const char *type, int write_object, const char *path) { @@ -49,87 +50,70 @@ static void hash_stdin_paths(const char *type, int write_objects) strbuf_release(&nbuf); } -static const char hash_object_usage[] = -"git hash-object [-t ] [-w] [--stdin] [--] ...\n" -" or: git hash-object --stdin-paths < "; +static const char * const hash_object_usage[] = { + "git hash-object [-t ] [-w] [--stdin] [--] ...", + "git hash-object --stdin-paths < ", + NULL +}; -int main(int argc, char **argv) +static const char *type; +static int write_object; +static int hashstdin; +static int stdin_paths; + +static const struct option hash_object_options[] = { + OPT_STRING('t', NULL, &type, "type", "object type"), + OPT_BOOLEAN('w', NULL, &write_object, "write the object into the object database"), + OPT_BOOLEAN( 0 , "stdin", &hashstdin, "read the object from stdin"), + OPT_BOOLEAN( 0 , "stdin-paths", &stdin_paths, "read file names from stdin"), + OPT_END() +}; + +int main(int argc, const char **argv) { int i; - const char *type = blob_type; - int write_object = 0; const char *prefix = NULL; int prefix_length = -1; - int no_more_flags = 0; - int hashstdin = 0; - int stdin_paths = 0; + const char *errstr = NULL; + + type = blob_type; git_config(git_default_config, NULL); - for (i = 1 ; i < argc; i++) { - if (!no_more_flags && argv[i][0] == '-') { - if (!strcmp(argv[i], "-t")) { - if (argc <= ++i) - usage(hash_object_usage); - type = argv[i]; - } - else if (!strcmp(argv[i], "-w")) { - if (prefix_length < 0) { - prefix = setup_git_directory(); - prefix_length = - prefix ? strlen(prefix) : 0; - } - write_object = 1; - } - else if (!strcmp(argv[i], "--")) { - no_more_flags = 1; - } - else if (!strcmp(argv[i], "--help")) - usage(hash_object_usage); - else if (!strcmp(argv[i], "--stdin-paths")) { - if (hashstdin) { - error("Can't use --stdin-paths with --stdin"); - usage(hash_object_usage); - } - stdin_paths = 1; - - } - else if (!strcmp(argv[i], "--stdin")) { - if (stdin_paths) { - error("Can't use %s with --stdin-paths", argv[i]); - usage(hash_object_usage); - } - if (hashstdin) - die("Multiple --stdin arguments are not supported"); - hashstdin = 1; - } - else - usage(hash_object_usage); - } - else { - const char *arg = argv[i]; - - if (stdin_paths) { - error("Can't specify files (such as \"%s\") with --stdin-paths", arg); - usage(hash_object_usage); - } - - if (hashstdin) { - hash_fd(0, type, write_object, NULL); - hashstdin = 0; - } - if (0 <= prefix_length) - arg = prefix_filename(prefix, prefix_length, - arg); - hash_object(arg, type, write_object); - no_more_flags = 1; - } + argc = parse_options(argc, argv, hash_object_options, hash_object_usage, 0); + + if (write_object) { + prefix = setup_git_directory(); + prefix_length = prefix ? strlen(prefix) : 0; } - if (stdin_paths) - hash_stdin_paths(type, write_object); + if (stdin_paths) { + if (hashstdin) + errstr = "Can't use --stdin-paths with --stdin"; + else if (argc) + errstr = "Can't specify files with --stdin-paths"; + } + else if (hashstdin > 1) + errstr = "Multiple --stdin arguments are not supported"; + + if (errstr) { + error (errstr); + usage_with_options(hash_object_usage, hash_object_options); + } if (hashstdin) hash_fd(0, type, write_object, NULL); + + for (i = 0 ; i < argc; i++) { + const char *arg = argv[i]; + + if (0 <= prefix_length) + arg = prefix_filename(prefix, prefix_length, arg); + hash_object(arg, type, write_object); + } + + if (stdin_paths) + hash_stdin_paths(type, write_object); + return 0; } From 39702431500b76425f047209c9e9b2aae7e92b00 Mon Sep 17 00:00:00 2001 From: Dmitry Potapov Date: Sun, 3 Aug 2008 18:36:21 +0400 Subject: [PATCH 5/6] add --path option to git hash-object The --path option allows us to pretend as if the contents being hashed came from the specified path, and affects which input filter is used via the attributes mechanism. This is useful for hashing a temporary file whose name is different from the path that is meant to have the hashed contents. Signed-off-by: Dmitry Potapov Signed-off-by: Junio C Hamano --- Documentation/git-hash-object.txt | 12 +++++++++++- hash-object.c | 19 +++++++++++++------ t/t1007-hash-object.sh | 24 ++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 7 deletions(-) diff --git a/Documentation/git-hash-object.txt b/Documentation/git-hash-object.txt index a4703ec0d..fececbf75 100644 --- a/Documentation/git-hash-object.txt +++ b/Documentation/git-hash-object.txt @@ -9,7 +9,7 @@ git-hash-object - Compute object ID and optionally creates a blob from a file SYNOPSIS -------- [verse] -'git hash-object' [-t ] [-w] [--stdin] [--] ... +'git hash-object' [-t ] [-w] [--path=] [--stdin] [--] ... 'git hash-object' [-t ] [-w] --stdin-paths < DESCRIPTION @@ -37,6 +37,16 @@ OPTIONS --stdin-paths:: Read file names from stdin instead of from the command-line. +--path:: + Hash object as it were located at the given path. The location of + file does not directly influence on the hash value, but path is + used to determine what git filters should be applied to the object + before it can be placed to the object database, and, as result of + applying filters, the actual blob put into the object database may + differ from the given file. This option is mainly useful for hashing + temporary files located outside of the working directory or files + read from stdin. + Author ------ Written by Junio C Hamano diff --git a/hash-object.c b/hash-object.c index 489e8369d..ce04d150a 100644 --- a/hash-object.c +++ b/hash-object.c @@ -22,13 +22,14 @@ static void hash_fd(int fd, const char *type, int write_object, const char *path maybe_flush_or_die(stdout, "hash to stdout"); } -static void hash_object(const char *path, const char *type, int write_object) +static void hash_object(const char *path, const char *type, int write_object, + const char *vpath) { int fd; fd = open(path, O_RDONLY); if (fd < 0) die("Cannot open %s", path); - hash_fd(fd, type, write_object, path); + hash_fd(fd, type, write_object, vpath); } static void hash_stdin_paths(const char *type, int write_objects) @@ -44,14 +45,14 @@ static void hash_stdin_paths(const char *type, int write_objects) die("line is badly quoted"); strbuf_swap(&buf, &nbuf); } - hash_object(buf.buf, type, write_objects); + hash_object(buf.buf, type, write_objects, buf.buf); } strbuf_release(&buf); strbuf_release(&nbuf); } static const char * const hash_object_usage[] = { - "git hash-object [-t ] [-w] [--stdin] [--] ...", + "git hash-object [-t ] [-w] [--path=] [--stdin] [--] ...", "git hash-object --stdin-paths < ", NULL }; @@ -60,12 +61,14 @@ static const char *type; static int write_object; static int hashstdin; static int stdin_paths; +static const char *vpath; static const struct option hash_object_options[] = { OPT_STRING('t', NULL, &type, "type", "object type"), OPT_BOOLEAN('w', NULL, &write_object, "write the object into the object database"), OPT_BOOLEAN( 0 , "stdin", &hashstdin, "read the object from stdin"), OPT_BOOLEAN( 0 , "stdin-paths", &stdin_paths, "read file names from stdin"), + OPT_STRING( 0 , "path", &vpath, "file", "process file as it were from this path"), OPT_END() }; @@ -85,6 +88,8 @@ int main(int argc, const char **argv) if (write_object) { prefix = setup_git_directory(); prefix_length = prefix ? strlen(prefix) : 0; + if (vpath && prefix) + vpath = prefix_filename(prefix, prefix_length, vpath); } if (stdin_paths) { @@ -92,6 +97,8 @@ int main(int argc, const char **argv) errstr = "Can't use --stdin-paths with --stdin"; else if (argc) errstr = "Can't specify files with --stdin-paths"; + else if (vpath) + errstr = "Can't use --stdin-paths with --path"; } else if (hashstdin > 1) errstr = "Multiple --stdin arguments are not supported"; @@ -102,14 +109,14 @@ int main(int argc, const char **argv) } if (hashstdin) - hash_fd(0, type, write_object, NULL); + hash_fd(0, type, write_object, vpath); for (i = 0 ; i < argc; i++) { const char *arg = argv[i]; if (0 <= prefix_length) arg = prefix_filename(prefix, prefix_length, arg); - hash_object(arg, type, write_object); + hash_object(arg, type, write_object, vpath ? vpath : arg); } if (stdin_paths) diff --git a/t/t1007-hash-object.sh b/t/t1007-hash-object.sh index 6d505fafe..f3972a79a 100755 --- a/t/t1007-hash-object.sh +++ b/t/t1007-hash-object.sh @@ -61,6 +61,10 @@ test_expect_success "Can't pass filenames as arguments with --stdin-paths" ' echo example | test_must_fail git hash-object --stdin-paths hello ' +test_expect_success "Can't use --path with --stdin-paths" ' + echo example | test_must_fail git hash-object --stdin-paths --path=foo +' + # Behavior push_repo @@ -93,6 +97,26 @@ test_expect_success 'git hash-object --stdin file1 file0 && + cp file0 file1 && + echo "file0 -crlf" >.gitattributes && + echo "file1 crlf" >>.gitattributes && + git config core.autocrlf true && + file0_sha=$(git hash-object file0) && + file1_sha=$(git hash-object file1) && + test "$file0_sha" != "$file1_sha" && + path1_sha=$(git hash-object --path=file1 file0) && + path0_sha=$(git hash-object --path=file0 file1) && + test "$file0_sha" = "$path0_sha" && + test "$file1_sha" = "$path1_sha" && + path1_sha=$(cat file0 | git hash-object --path=file1 --stdin) && + path0_sha=$(cat file1 | git hash-object --path=file0 --stdin) && + test "$file0_sha" = "$path0_sha" && + test "$file1_sha" = "$path1_sha" && + git config --unset core.autocrlf +' + pop_repo for args in "-w --stdin" "--stdin -w"; do From 4a3d85dcf6722b7e5d16b5b1f69b51e39ad5f1dc Mon Sep 17 00:00:00 2001 From: Dmitry Potapov Date: Sun, 3 Aug 2008 18:36:22 +0400 Subject: [PATCH 6/6] add --no-filters option to git hash-object The new option allows the contents to be hashed as is, ignoring any input filter that would have been chosen by the attributes mechanism. This option is incompatible with --path and --stdin-paths options. Signed-off-by: Dmitry Potapov Signed-off-by: Junio C Hamano --- Documentation/git-hash-object.txt | 8 +++++++- hash-object.c | 17 +++++++++++++---- t/t1007-hash-object.sh | 24 ++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 5 deletions(-) diff --git a/Documentation/git-hash-object.txt b/Documentation/git-hash-object.txt index fececbf75..0af40cfb8 100644 --- a/Documentation/git-hash-object.txt +++ b/Documentation/git-hash-object.txt @@ -9,7 +9,7 @@ git-hash-object - Compute object ID and optionally creates a blob from a file SYNOPSIS -------- [verse] -'git hash-object' [-t ] [-w] [--path=] [--stdin] [--] ... +'git hash-object' [-t ] [-w] [--path=|--no-filters] [--stdin] [--] ... 'git hash-object' [-t ] [-w] --stdin-paths < DESCRIPTION @@ -47,6 +47,12 @@ OPTIONS temporary files located outside of the working directory or files read from stdin. +--no-filters:: + Hash the contents as is, ignoring any input filter that would + have been chosen by the attributes mechanism, including crlf + conversion. If the file is read from standard input then this + is always implied, unless the --path option is given. + Author ------ Written by Junio C Hamano diff --git a/hash-object.c b/hash-object.c index ce04d150a..a4d127cf7 100644 --- a/hash-object.c +++ b/hash-object.c @@ -52,7 +52,7 @@ static void hash_stdin_paths(const char *type, int write_objects) } static const char * const hash_object_usage[] = { - "git hash-object [-t ] [-w] [--path=] [--stdin] [--] ...", + "git hash-object [-t ] [-w] [--path=|--no-filters] [--stdin] [--] ...", "git hash-object --stdin-paths < ", NULL }; @@ -61,6 +61,7 @@ static const char *type; static int write_object; static int hashstdin; static int stdin_paths; +static int no_filters; static const char *vpath; static const struct option hash_object_options[] = { @@ -68,6 +69,7 @@ static const struct option hash_object_options[] = { OPT_BOOLEAN('w', NULL, &write_object, "write the object into the object database"), OPT_BOOLEAN( 0 , "stdin", &hashstdin, "read the object from stdin"), OPT_BOOLEAN( 0 , "stdin-paths", &stdin_paths, "read file names from stdin"), + OPT_BOOLEAN( 0 , "no-filters", &no_filters, "store file as is without filters"), OPT_STRING( 0 , "path", &vpath, "file", "process file as it were from this path"), OPT_END() }; @@ -99,9 +101,15 @@ int main(int argc, const char **argv) errstr = "Can't specify files with --stdin-paths"; else if (vpath) errstr = "Can't use --stdin-paths with --path"; + else if (no_filters) + errstr = "Can't use --stdin-paths with --no-filters"; + } + else { + if (hashstdin > 1) + errstr = "Multiple --stdin arguments are not supported"; + if (vpath && no_filters) + errstr = "Can't use --path with --no-filters"; } - else if (hashstdin > 1) - errstr = "Multiple --stdin arguments are not supported"; if (errstr) { error (errstr); @@ -116,7 +124,8 @@ int main(int argc, const char **argv) if (0 <= prefix_length) arg = prefix_filename(prefix, prefix_length, arg); - hash_object(arg, type, write_object, vpath ? vpath : arg); + hash_object(arg, type, write_object, + no_filters ? NULL : vpath ? vpath : arg); } if (stdin_paths) diff --git a/t/t1007-hash-object.sh b/t/t1007-hash-object.sh index f3972a79a..fcdd15a35 100755 --- a/t/t1007-hash-object.sh +++ b/t/t1007-hash-object.sh @@ -65,6 +65,14 @@ test_expect_success "Can't use --path with --stdin-paths" ' echo example | test_must_fail git hash-object --stdin-paths --path=foo ' +test_expect_success "Can't use --stdin-paths with --no-filters" ' + echo example | test_must_fail git hash-object --stdin-paths --no-filters +' + +test_expect_success "Can't use --path with --no-filters" ' + test_must_fail git hash-object --no-filters --path=foo +' + # Behavior push_repo @@ -117,6 +125,22 @@ test_expect_success 'check that appropriate filter is invoke when --path is used git config --unset core.autocrlf ' +test_expect_success 'check that --no-filters option works' ' + echo fooQ | tr Q "\\015" >file0 && + cp file0 file1 && + echo "file0 -crlf" >.gitattributes && + echo "file1 crlf" >>.gitattributes && + git config core.autocrlf true && + file0_sha=$(git hash-object file0) && + file1_sha=$(git hash-object file1) && + test "$file0_sha" != "$file1_sha" && + nofilters_file1=$(git hash-object --no-filters file1) && + test "$file0_sha" = "$nofilters_file1" && + nofilters_file1=$(cat file1 | git hash-object --stdin) && + test "$file0_sha" = "$nofilters_file1" && + git config --unset core.autocrlf +' + pop_repo for args in "-w --stdin" "--stdin -w"; do