jacogr / atom-git-control

Not maintained :(
MIT License
227 stars 70 forks source link

Compare doesn't work #40

Open sixrandanes opened 9 years ago

sixrandanes commented 9 years ago

Hello,

When I click on compare command, I have that issue : cannot read property 'push' of undefined. I'am using atom version 0.184.0. screenshot

Thanks

kylekatarnls commented 9 years ago

Same issue, when I installed git:control, it worked, now, I get this issue. Atom Windows 0.194.0, git-control 0.2.0

MarcelMue commented 9 years ago

Can you post a screenshot like the one above? I have a feeling that this issue is related to Atom not properly recognizing your project as a git repository. ( See the icon in the top image is a normal folder, not a repository icon the way it normally is)

hellerbarde commented 9 years ago

@MarcelMue the icon isn't a good indicator of this. I have a project some levels deep inside a git repository and Atom has no problem displaying the changes in the left margin. Oh and it also does not display it as a book.

codingsteff commented 9 years ago

Same issue.

Cannot read property 'push' of undefined
PlaidPhantom commented 9 years ago

I have the same problem. running the command "git --no-pager diff" from both git bash and the Command Promp seems to work fine.

kantholy commented 8 years ago

any updates on that issue? it's still occuring...

hellt commented 8 years ago

same occurs on my project. It is not 100% reproducible though.

diegonc commented 8 years ago

Hello, I debugged this issue and think that I know what's going on.

When Compare button is clicked git-control will run git diff command and parse its output. The following is an excerpt of that output.

warning: LF will be replaced by CRLF in src/elm/Main.elm.
The file will have its original line endings in your working directory.
diff --git a/README.md b/README.md
index a72397a..9867dcd 100644
--- a/README.md
+++ b/README.md
@@ -159,3 +159,51 @@ according to the model.
           div.ball

And the relevant parsing code can located at git.coffee#42, in a function that is quoted below for reference.

parseDiff = (data) -> q.fcall ->
  diffs = []
  diff = {}
  for line in data.split('\n') when line.length
    switch
      when /^diff --git /.test(line)
        diff =
          lines: []
          added: 0
          removed: 0
        diff['diff'] = line.replace(/^diff --git /, '')
        diffs.push diff
      when /^index /.test(line)
        diff['index'] = line.replace(/^index /, '')
      when /^--- /.test(line)
        diff['---'] = line.replace(/^--- [a|b]\//, '')
      when /^\+\+\+ /.test(line)
        diff['+++'] = line.replace(/^\+\+\+ [a|b]\//, '')
      else
        diff['lines'].push line
        diff['added']++ if /^\+/.test(line)
        diff['removed']++ if /^-/.test(line)

  return diffs

The first two lines git prints are just warnings regarding line ending handling in Windows, however they are not being filtered. Thus, the first iteration of the for loop will enter the switch in the else branch while diff is still uninitialized (it will not be assigned valid data until handling line 3 of the output) which leads to trying to call push of undefined.

What I think it would help is to do as in the following "pseudo-patch":

         diff['+++'] = line.replace(/^\+\+\+ [a|b]\//, '')
-      else
+      when /^[ +-]/.test(line)
         diff['lines'].push line
         diff['added']++ if /^\+/.test(line)
         diff['removed']++ if /^-/.test(line)
+      else
+        # Do whatever you want with non-diff lines
+        continue # such as ignoring them
kantholy commented 8 years ago

another option would be to "initialize" the object before the switch statement - or am I wrong?

parseDiff = (data) -> q.fcall ->
  diffs = []
- diff = {}
+ diff = {
+   lines: [],
+   added: 0,
+   removed: 0
+ }
  for line in data.split('\n') when line.length
    switch
      when /^diff --git /.test(line)
-       diff =
-         lines: []
-         added: 0
-         removed: 0
        diff['diff'] = line.replace(/^diff --git /, '')
        diffs.push diff
diegonc commented 8 years ago

That will break when there are many diff lines in the same output. Each of them start a new diffobject that needs to be pushed into diffsarray.

karneaud commented 7 years ago

+1 bump same issue even with a similar package

mikolaj-kow commented 7 years ago

I've tested your patch and it solves the issue. Thanks