Commit graph

6 commits

Author SHA1 Message Date
Ævar Arnfjörð Bjarmason 9081a421a6 checkout: fix "branch info" memory leaks
The "checkout" command is one of the main sources of leaks in the test
suite, let's fix the common ones by not leaking from the "struct
branch_info".

Doing this is rather straightforward, albeit verbose, we need to
xstrdup() constant strings going into the struct, and free() the ones
we clobber as we go along.

This also means that we can delete previous partial leak fixes in this
area, i.e. the "path_to_free" accounting added by 96ec7b1e70 (Convert
resolve_ref+xstrdup to new resolve_refdup function, 2011-12-13).

There was some discussion about whether "we should retain the "const
char *" here and cast at free() time, or have it be a "char *". Since
this is not a public API with any sort of API boundary let's use
"char *", as is already being done for the "refname" member of the
same struct.

The tests to mark as passing were found with:

    rm .prove; GIT_SKIP_TESTS=t0027 prove -j8 --state=save t[0-9]*.sh :: --immediate
    # apply & compile this change
    prove -j8 --state=failed :: --immediate

I.e. the ones that were newly passing when the --state=failed command
was run. I left out "t3040-subprojects-basic.sh" and
"t4131-apply-fake-ancestor.sh" to to optimization-level related
differences similar to the ones noted in[1], except that these would
be something the current 'linux-leaks' job would run into.

1. https://lore.kernel.org/git/cover-v3-0.6-00000000000-20211022T175227Z-avarab@gmail.com/

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-11-18 14:32:26 -08:00
Johannes Schindelin 38f9912ff9 t3040: remove stale note
This comment was most likely a "note to self" during the development of
1c3e5c4ebc (Tests for core subproject support, 2007-04-19) and is
neither needed nor comprehensible at this point. Let's remove it.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-11-18 12:38:34 -08:00
Ann T Ropea a2cd709de3 print_sha1_ellipsis: introduce helper
Introduce a helper print_sha1_ellipsis() that pays attention to the
GIT_PRINT_SHA1_ELLIPSIS environment variable, and prepare the tests to
unconditionally set it for the test pieces that will be broken once the code
stops showing the extra dots by default.

The removal of these dots is merely a plan at this step and has not happened
yet but soon will.

Document GIT_PRINT_SHA1_ELLIPSIS.

Signed-off-by: Ann T Ropea <bedhanger@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-12-04 08:25:35 -08:00
Ramkumar Ramachandra 5e11362271 t3040 (subprojects-basic): fix '&&' chaining, modernize style
Breaks in a test assertion's && chain can potentially hide failures
from earlier commands in the chain.  Fix instances of this.  While at
it, clean up the style to fit the prevailing style.  This means:

- Put the opening quote starting each test on the same line as the
  test_expect_* invocation.

- Indent the file with tabs, not spaces.

- Use test_expect_code() in preference to checking the exit status of
  various statements by hand.

- Guard commands that prepare test input for individual tests in the
  same test_expect_success, so that their scope is clearer and errors
  at that stage can be caught.

- Use <<-\EOF in preference to <<EOF to save readers the trouble of
  looking for variable interpolations.

- Include "setup" in the titles of test assertions that prepare for
  later ones to make it more obvious which tests can be skipped.

Helped-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-12-09 11:30:42 -08:00
Junio C Hamano 3af828634f tests: do not use implicit "git diff --no-index"
As a general principle, we should not use "git diff" to validate the
results of what git command that is being tested has done.  We would not
know if we are testing the command in question, or locating a bug in the
cute hack of "git diff --no-index".

Rather use test_cmp for that purpose.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-05-24 00:01:56 -07:00
Alex Riesen 1c3e5c4ebc Tests for core subproject support
The following tests available:

- create subprojects: create a directory in the superproject,
  initialize a git repo in it, and try adding it in super project.
  Make a commit in superproject

- check if fsck ignores the subprojects: it just should give no errors

- check if commit in a subproject detected: make a commit in
  subproject, git-diff-files in superproject should detect it

- check if a changed subproject HEAD can be committed: try
  "git-commit -a" in superproject. It should commit changed
  HEAD of a subproject

- check if diff-index works for subproject elements: compare the index
  (changed by previuos tests) with the initial commit (which created
  two subprojects). Should show a change for the recently changed subproject

- check if diff-tree works for subproject elements: do the same, just use
  git-diff-tree. This test is somewhat redundant, I just added it for
  completeness (diff, diff-files, and diff-index are already used)

- check if git diff works for subproject elements: try to limit
  the diff for the name of a subproject in superproject:
     git diff HEAD^ HEAD -- subproject

- check if clone works: try a clone of superproject and compare
  "git ls-files -s" output in superproject and cloned repo

- removing and adding subproject: rename test. Currently implemented
  as "git-update-index --force-remove", "mv" and "git-add".

- checkout in superproject: try to checkout the initial commit

Signed-off-by: Alex Riesen <raa.lkml@gmail.com>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-04-18 17:08:42 -07:00