# [StGit PATCH 1/2] Handle "git diff-tree --stdin" error

2 messages from 2008-10-09 to 2008-10-09. Participants: Samuel Tardieu.
Thread: https://gitlist.dev/t/15832

## Samuel Tardieu, 2008-10-09 09:01

Subject: [StGit PATCH 1/2] Handle "git diff-tree --stdin" error
Message-ID: <20081009090157.12637.45887.stgit@arrakis.enst.fr>
URL: https://gitlist.dev/e/20081009090157.12637.45887.stgit%40arrakis.enst.fr

```
If, for any reason, one of the SHA1 is not a commit object,
"git diff-tree --stdin" will signal an error on its standard
error and will only issue the requested "end" pattern.

"stg diff" could wait forver for the right references to
happen. With this patch, we now get:

% stg diff
stg diff: error: Object 6daaab2215a3d277a315d6938bdda86b2f75f6af not a commit
---
 stgit/lib/git.py |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/stgit/lib/git.py b/stgit/lib/git.py
index 4f210f8..45c0b32 100644
--- a/stgit/lib/git.py
+++ b/stgit/lib/git.py
@@ -579,10 +579,10 @@ class DiffTreeProcesses(object):
         p.stdin.write(query + end)
         p.stdin.flush()
         s = ''
-        while not (s.endswith('\n' + end) or s.endswith('\0' + end)):
+        while not s.endswith(end):
             s += os.read(p.stdout.fileno(), 4096)
-        assert s.startswith(query)
-        assert s.endswith(end)
+        if not s.startswith(query):
+            raise RepositoryException(os.read(p.stderr.fileno(), 4096))
         return s[len(query):-len(end)]
 
 class Repository(RunWithEnv):

```

## Samuel Tardieu, 2008-10-09 09:02

Subject: [StGit PATCH 2/2] Always resolve "git describe" to something
Message-ID: <20081009090202.12637.2907.stgit@arrakis.enst.fr>
URL: https://gitlist.dev/e/20081009090202.12637.2907.stgit%40arrakis.enst.fr
In-Reply-To: <20081009090157.12637.45887.stgit@arrakis.enst.fr>

```
Sometimes, "git describe" cannot describe the current version. Use
"--always" so that we have a fallback.
---
 stgit/version.py |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/stgit/version.py b/stgit/version.py
index d57053d..05fa8e9 100644
--- a/stgit/version.py
+++ b/stgit/version.py
@@ -8,7 +8,7 @@ class VersionUnavailable(StgException):
 def git_describe_version():
     path = sys.path[0]
     try:
-        v = run.Run('git', 'describe', '--tags', '--abbrev=4'
+        v = run.Run('git', 'describe', '--tags', '--abbrev=4', '--always'
                     ).cwd(path).output_one_line()
     except run.RunException, e:
         raise VersionUnavailable(str(e))

```
