# [PATCHv2 1/2] git-p4: demonstrate `unshelve` bug

4 messages from 2020-09-20 to 2020-09-20. Participants: Luke Diamand, Eric Sunshine.
Thread: https://gitlist.dev/t/54263

## Luke Diamand, 2020-09-20 07:48

Subject: [PATCHv2 1/2] git-p4: demonstrate `unshelve` bug
Message-ID: <20200920074841.17043-2-luke@diamand.org>
URL: https://gitlist.dev/e/20200920074841.17043-2-luke%40diamand.org
In-Reply-To: <20200920074841.17043-1-luke@diamand.org>

```
`git-p4 unshelve` uses HEAD^$n to find the parent commit, which
fails if there is an additional commit. Augment the tests to demonstrate
this problem.

Signed-off-by: Luke Diamand <luke@diamand.org>
---
 t/t9832-unshelve.sh | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/t/t9832-unshelve.sh b/t/t9832-unshelve.sh
index e9276c48f4..feda4499dd 100755
--- a/t/t9832-unshelve.sh
+++ b/t/t9832-unshelve.sh
@@ -29,8 +29,11 @@ test_expect_success 'init depot' '
 	)
 '
 
+# Create an initial clone, with a commit unrelated to the P4 change
+# on HEAD
 test_expect_success 'initial clone' '
-	git p4 clone --dest="$git" //depot/@all
+	git p4 clone --dest="$git" //depot/@all &&
+    test_commit -C "$git" "unrelated"
 '
 
 test_expect_success 'create shelved changelist' '
@@ -77,7 +80,7 @@ EOF
 	)
 '
 
-test_expect_success 'update shelved changelist and re-unshelve' '
+test_expect_failure 'update shelved changelist and re-unshelve' '
 	test_when_finished cleanup_git &&
 	(
 		cd "$cli" &&
-- 
2.20.1.390.gb5101f9297


```

## Luke Diamand, 2020-09-20 07:48

Subject: [PATCHv2 0/2] git-p4: unshelve uses HEAD^n, not HEAD~n
Message-ID: <20200920074841.17043-1-luke@diamand.org>
URL: https://gitlist.dev/e/20200920074841.17043-1-luke%40diamand.org

```
Updated commits incorporating comments from Eric Sunshine.

Luke Diamand (2):
  git-p4: demonstrate `unshelve` bug
  git-p4: fix `unshelve` bug finding parent commit

 git-p4.py           | 2 +-
 t/t9832-unshelve.sh | 5 ++++-
 2 files changed, 5 insertions(+), 2 deletions(-)

-- 
2.20.1.390.gb5101f9297


```

## Luke Diamand, 2020-09-20 07:48

Subject: [PATCHv2 2/2] git-p4: fix `unshelve` bug finding parent commit
Message-ID: <20200920074841.17043-3-luke@diamand.org>
URL: https://gitlist.dev/e/20200920074841.17043-3-luke%40diamand.org
In-Reply-To: <20200920074841.17043-2-luke@diamand.org>

```
`unshelve` was using HEAD^$n to find the parent commit. This meant that
any intervening commits between HEAD and the last git-p4 commit would
cause the unshelve to fail.

e.g.
    123ab Local git-only commit
    234bc Another local git-only commit
    345cd Perforce tip revision

Unshelve needs to find 345cd.

Use HEAD~$n instead.

Reported-by: Liu Xuhui (Jackson) <Xuhui.Liu@amd.com>
Signed-off-by: Luke Diamand <luke@diamand.org>
---
 git-p4.py           | 2 +-
 t/t9832-unshelve.sh | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/git-p4.py b/git-p4.py
index ca79dc0900..4433ca53de 100755
--- a/git-p4.py
+++ b/git-p4.py
@@ -4237,7 +4237,7 @@ def findLastP4Revision(self, starting_point):
         """
 
         for parent in (range(65535)):
-            log = extractLogMessageFromGitCommit("{0}^{1}".format(starting_point, parent))
+            log = extractLogMessageFromGitCommit("{0}~{1}".format(starting_point, parent))
             settings = extractSettingsGitLog(log)
             if 'change' in settings:
                 return settings
diff --git a/t/t9832-unshelve.sh b/t/t9832-unshelve.sh
index feda4499dd..7194fb2855 100755
--- a/t/t9832-unshelve.sh
+++ b/t/t9832-unshelve.sh
@@ -80,7 +80,7 @@ EOF
 	)
 '
 
-test_expect_failure 'update shelved changelist and re-unshelve' '
+test_expect_success 'update shelved changelist and re-unshelve' '
 	test_when_finished cleanup_git &&
 	(
 		cd "$cli" &&
-- 
2.20.1.390.gb5101f9297


```

## Eric Sunshine, 2020-09-20 08:40

Subject: Re: [PATCHv2 1/2] git-p4: demonstrate `unshelve` bug
Message-ID: <CAPig+cQiJBC4+T3Cqg==1aNoe_DULLZ=BTQoNnygJXZvTLJu0A@mail.gmail.com>
URL: https://gitlist.dev/e/CAPig%2BcQiJBC4%2BT3Cqg%3D%3D1aNoe_DULLZ%3DBTQoNnygJXZvTLJu0A%40mail.gmail.com
In-Reply-To: <20200920074841.17043-2-luke@diamand.org>

```
On Sun, Sep 20, 2020 at 3:48 AM Luke Diamand <luke@diamand.org> wrote:
> +# Create an initial clone, with a commit unrelated to the P4 change
> +# on HEAD
>  test_expect_success 'initial clone' '
> -       git p4 clone --dest="$git" //depot/@all
> +       git p4 clone --dest="$git" //depot/@all &&
> +    test_commit -C "$git" "unrelated"
>  '

The indentation of the new line is still bad[1].

[1]: https://lore.kernel.org/git/CAPig+cSx35oTR_Er-DyxqV0HZw+tDHPf1GdARfw=-2bhTz02gw@mail.gmail.com/

```
