felipec / git-reintegrate

Tool that allows the regeneration of integration branches
22 stars 8 forks source link

Invoking from newly created subdirectory fails #7

Closed uu1101 closed 8 years ago

uu1101 commented 10 years ago

The following test case shows the issue. Note that the commit_file function has been updated to be able to create files in a directory.

commit_file() {
    local filename="$1"
    local dirname="$(dirname $filename)"
    test -d $dirname || mkdir -p $dirname
    echo "$2" > $filename &&
    git add -f $filename &&
    git commit -q -m "commit $filename"
}

write_script .git/EDITOR <<\EOF &&
#!/bin/sh
cat > "$1" <<EOM
base master
merge branch1
merge branch2
merge branch3
merge branch4
EOM
EOF

test_expect_success 'invoking from new subfolder should not fail' '
    git checkout -b branch4 master &&
    commit_file dir4/branch4 branch4 &&
    GIT_EDITOR=.git/EDITOR git reintegrate --edit pu &&
    git reintegrate --rebuild pu &&
    git checkout branch4 &&
    cd dir4 &&
    git reintegrate --rebuild pu
'

What should the solution look like? Should

felipec commented 9 years ago

I'm not entirely sure. I think the second option is bet: run on the top level directory.

uu1101 commented 9 years ago

Hello,

Glad to see you back. Yes, what about the following?

diff --git i/git-reintegrate w/git-reintegrate
index 44bf054..39121f7 100755
--- i/git-reintegrate
+++ w/git-reintegrate
@@ -687,6 +687,9 @@ $autocontinue = true

 opts.parse

+$git_cdup = %x[git rev-parse --show-cdup].chomp
+die "You need to run this command from the toplevel of the working tree." unless $git_cdup.empty?
+
 $git_dir = %x[git rev-parse --git-dir].chomp

 $state_dir = "#{$git_dir}/integration"
diff --git i/test/reintegrate.t w/test/reintegrate.t
index 41dddd0..b260dbd 100755
--- i/test/reintegrate.t
+++ w/test/reintegrate.t
@@ -206,14 +206,14 @@ merge branch4
 EOM
 EOF

-test_expect_success 'invoking from new subfolder should not fail' '
+test_expect_success 'invoking from subfolder should fail' '
    git checkout -b branch4 master &&
    commit_file dir4/branch4 branch4 &&
    GIT_EDITOR=.git/EDITOR git reintegrate --edit pu &&
    git reintegrate --rebuild pu &&
    git checkout branch4 &&
    cd dir4 &&
-   git reintegrate --rebuild pu
+   test_must_fail git reintegrate --rebuild pu
 '

 test_done
felipec commented 8 years ago

Done. I didn't add the test, but I checked it. Fixed in 094ddf9.