Giter Site home page Giter Site logo

Compare doesn't work about atom-git-control HOT 12 OPEN

jacogr avatar jacogr commented on July 17, 2024 1
Compare doesn't work

from atom-git-control.

Comments (12)

codingsteff avatar codingsteff commented on July 17, 2024 1

Same issue.

Cannot read property 'push' of undefined

from atom-git-control.

kylekatarnls avatar kylekatarnls commented on July 17, 2024

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

from atom-git-control.

MarcelMue avatar MarcelMue commented on July 17, 2024

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)

from atom-git-control.

hellerbarde avatar hellerbarde commented on July 17, 2024

@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.

from atom-git-control.

PlaidPhantom avatar PlaidPhantom commented on July 17, 2024

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

from atom-git-control.

kantholy avatar kantholy commented on July 17, 2024

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

from atom-git-control.

hellt avatar hellt commented on July 17, 2024

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

from atom-git-control.

diegonc avatar diegonc commented on July 17, 2024

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

from atom-git-control.

kantholy avatar kantholy commented on July 17, 2024

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

from atom-git-control.

diegonc avatar diegonc commented on July 17, 2024

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.

from atom-git-control.

karneaud avatar karneaud commented on July 17, 2024

+1 bump same issue even with a similar package

from atom-git-control.

mikolaj-kow avatar mikolaj-kow commented on July 17, 2024

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

from atom-git-control.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.